Clicky

Fortran Wiki
associate

Associate

The associate construct yields simple abbreviations for more complex statements. It can be an alias for expressions or variables. See the following example

program associateTest

  implicit none
  integer :: a=1,b=1
  associate( x => a*b )
    print *, x                ! yields: 1
    a=10
    print *, x                ! yields: 1
  end associate

  associate( x => a )
    print *, x                ! yields: 10
    a=100
    print *, x                ! yields: 100
  end associate

end program associateTest

One can also name associate for more clarity in larger programs

program associateTest

  implicit none
  integer :: a=1,b=1
  someName: associate( x => a*b )
    print *, x                ! yields: 1
    a=10
    print *, x                ! yields: 1
  end associate someName

end program associateTest