The DO statement contains the following constructs.
A labeled DO loop consists of the following:
DO statement
Set of executable statements called a block
Terminal statement, usually a CONTINUE statement
The statement identified by s is called the terminal statement. It must follow the DO statement in the sequence of statements within the same program unit as the DO statement.
The terminal statement should not be one of the following statements:
Unconditional GO TO
Assigned GO TO
Arithmetic IF
Block IF/ELSE IF
ELSE
END IF
RETURN
STOP
END DO
If the terminal statement is a logical IF statement, it can contain any executable statement, except:
DO/DO WHILE
Block IF/ELSE IF
ELSE IF
ELSE
END IF
END
Logical IF
The range of a DO loop consists of all of the executable statements that appear following the DO statement, up to and including the terminal statement.
If a DO statement appears within the range of another DO loop, its range must be entirely contained within the range of the outer DO loop. More than one labeled DO loop can have the same terminal statement.
If a DO statement appears within an IF, ELSE IF, or ELSE block, the range of the associated DO loop must be contained entirely within that block.
If a block IF statement appears within the range of a DO loop, the corresponding END IF statement must also appear within the range of that DO loop.
A block DO loop consists of:
DO statement
Set of executable statements called a block
Terminal statement, an END DO statement
This loop is nonstandard.
Execution proceeds as follows:
The expressions e1, e2, and e3 are evaluated. If e3 is not present, its value is assumed to be one.
The DO variable is initialized with the value of e1.
The iteration count is established as the value of the expression:
MAX (INT ((e2 - e1 + e3)/),e3 0)
The iteration count is zero if either of the following is true:
e1 > e2 and e3 > zero.
e1 < e2 and e3 < zero.
If the -onetrip compile time option is specified, then the iteration count is never less than one.
The iteration count is tested, and, if it is greater than zero, the range of the DO loop is executed.
After the terminal statement of a DO loop is executed, the following steps are performed: