FORTRAN Reference Manual

Statements
FORTRAN Reference Manual528615-001
7-28
DO Statement
1. The expressions iexp, fexp, and incr are evaluated and converted to the
type of the control variable var if necessary.
2. The control variable is assigned the value of iexp.
3. The iteration count is calculated according to the following expression:
MAX(INT(( fexp - iexp + incr)/ incr),0)
The INT function truncates the result of the expression to an integer value; the
MAX function selects the larger of that value or zero. For example, the
statement
DO 100 j = 1,27,3
generates an iteration count of 9.
4. If the iteration count is not zero, the DO loop executes. If the iteration count is
zero, execution continues with the statement following the terminal statement
of the DO loop; the control variable retains its most recent value.
5. The control variable is incremented by the value of incr.
6. The iteration count is decremented by 1.
7. Steps 4 through 6 are repeated until the iteration count equals zero.
If the DO loop executes zero times, the control variable is equal to iexp.
Otherwise, the control variable is equal to its most recent value plus the value of
incr.
If the DO loop becomes inactive before the iteration count equals zero, the control
variable retains its most recent value. A DO loop becomes inactive if you execute a
GO TO statement that branches outside of the range of the DO loop.
The control variable retains its most recent value if:
°
A RETURN statement is executed within the range of the DO loop.
°
A STOP statement in the executable program is executed, or execution is
terminated for any other reason.
The last statement of a DO loop must not be any of the following:
°
A nonexecutable statement
°
An unconditional or assigned GO TO statement
°
An arithmetic or block-IF statement
°
An ELSE, ELSE IF, or END IF statement
°
A DO statement
°
A RETURN statement
°
A STOP statement