next up previous
Next: SELECT CASE Construct Up: Control Flow Previous: Examples of Loop Counts

 

Scope of DO Variables

Fortran 90 is not block structured, all DO variables are visible after the loop and have a specific value. The index variable is recalculated at the top of the loop and then compared with tex2html_wrap_inline21419  expr2 tex2html_wrap_inline21421 , if the loop has finished, execution jumps to the statement after the corresponding END DO. The loop is executed three times and i is assigned to 4 times, the index variable will retain the value that it had just been assigned. For example,

    DO i = 4, 45, 17
     PRINT*, "I in loop = ",i
    END DO
    PRINT*, "I after loop = ",i

will produce

    I in loop =  4
    I in loop =  21
    I in loop =  38
    I after loop =  55

Elsewhere in program the index variable may be used freely but in the loop it can only be referenced and must not have its value changed.


next up previous
Next: SELECT CASE Construct Up: Control Flow Previous: Examples of Loop Counts

Adam Marshall ©University of Liverpool, 1996
Wed Oct 9 17:57:29 BST 1996