Purpose
The DO statement controls the execution of the statements that follow it, up to and including a specified terminal statement. Together, these statements form a DO construct.
Format
>>-+----------------------+--DO--+------------+-----------------> '-DO_construct_name--:-' '-stmt_label-' >--+---------------------------------------------------+------->< '-+---+-var_name = a_expr1, a_expr2--+------------+-' '-,-' '- , a_expr3-' |
If you specify a DO_construct_name on the DO statement, you must terminate the construct with an END DO and the same DO_construct_name. Conversely, if you do not specify a DO_construct_name on the DO statement, and you terminate the DO construct with an END DO statement, you must not have a DO_construct_name on the END DO statement.
If you specify a statement label in the DO statement, you must terminate the DO construct with a statement that is labeled with that statement label. You can terminate a labeled DO statement with an END DO statement that is labeled with that statement label, but you cannot terminate it with an unlabeled END DO statement. If you do not specify a label in the DO statement, you must terminate the DO construct with an END DO statement.
If the control clause (the clause beginning with var_name) is absent, the statement is an infinite DO. The loop will iterate indefinitely until interrupted (for example, by the EXIT statement).
INTEGER :: SUM=0 OUTER: DO INNER: DO M=1,10 READ (5,*) J IF (J.LE.I) THEN PRINT *, 'VALUE MUST BE GREATER THAN ', I CYCLE INNER END IF SUM=SUM+J IF (SUM.GT.500) EXIT OUTER IF (SUM.GT.100) EXIT INNER END DO INNER SUM=SUM+I I=I+10 END DO OUTER PRINT *, 'SUM =',SUM END
Related Information