Executing a DO statement
An infinite DO does not have an iteration count limit or a termination condition.
If the loop is not an infinite DO, the DO
statement includes an initial parameter, a terminal parameter, and an optional increment.
- The initial parameter, m1, the terminal parameter, m2, and the increment, m3, are established by evaluating the DO statement expressions (a_expr1, a_expr2, and a_expr3, respectively). Evaluation includes, if necessary, conversion to the type of the DO variable according to the rules for arithmetic conversion. (See Arithmetic conversion.) If you do not specify a_expr3, m3 has a value of 1. m3 must not have a value of zero.
- The DO variable becomes defined with the value of the initial parameter (m1).
- The iteration count is determined by the expression:
Note that the iteration count is 0 whenever:MAX (INT ( (m2 - m1 + m3) / m3), 0)m1 > m2 and m3 > 0, orm1 < m2 and m3 < 0
The iteration count cannot be calculated if the DO variable is missing. This is referred to as an infinite DO construct.
The
iteration count cannot exceed 2**31 - 1 for integer variables of kind 1, 2, or 4, and cannot exceed
2**63 - 1 for integer variables of kind 8. The count becomes undefined if an overflow or underflow
situation arises during the calculation.
At the completion of the DO statement, loop control processing begins.