Intel® Fortran Compiler 16.0 User and Reference Guide
Statement: Marks the beginning of a DO construct. The DO construct controls the repeated execution of a block of statements or constructs. This repeated execution is called a loop.
A DO construct takes one of the following forms:
Block Form:
[name:] DO [label[, ] ] [loop-control]
block
[label] term-stmt
Nonblock Form:
DO label [,] [loop-control]
block
[label] ex-term-stmt
name |
(Optional) Is the name of the DO construct. |
label |
(Optional) Is a statement label identifying the terminal statement. |
loop-control |
Is one of the following:
|
block |
Is a sequence of zero or more statements or constructs that make up the DO range. |
term-stmt |
Is the terminal statement for the block form of the construct. |
ex-term-stmt |
Is the terminal statement for the nonblock form of the construct. |
The terminal statement (term-stmt) for a block DO construct is an END DO or CONTINUE statement. If the block DO statement contains a label, the terminal statement must be identified with the same label. If no label appears, the terminal statement must be an END DO statement.
If a construct name is specified in a block DO statement, the same name must appear in the terminal END DO statement. If no construct name is specified in the block DO statement, no name can appear in the terminal END DO statement.
The terminal statement (ex-term-stmt) for a nonblock DO construct is an executable statement (or construct) that is identified by the label specified in the nonblock DO statement. A nonblock DO construct can share a terminal statement with another nonblock DO construct. A block DO construct cannot share a terminal statement.
The following cannot be terminal statements for nonblock DO constructs:
CONTINUE (allowed if it is a shared terminal statement)
CYCLE
END (for a program or subprogram)
EXIT
GO TO (unconditional or assigned)
Arithmetic IF
RETURN
STOP
The nonblock DO construct is an obsolescent feature in Standard Fortran.
The following example shows a simple block DO construct (contains no iteration count or DO WHILE statement):
DO READ *, N IF (N == 0) STOP CALL SUBN END DO
The DO block executes repeatedly until the value of zero is read. Then the DO construct terminates.
The following example shows a named block DO construct:
LOOP_1: DO I = 1, N A(I) = C * B(I) END DO LOOP_1
The following example shows a nonblock DO construct with a shared terminal statement:
DO 20 I = 1, N DO 20 J = 1 + I, N 20 RESULT(I,J) = 1.0 / REAL(I + J)
The following two program fragments are also examples of DO statements:
C Initialize the even elements of a 20-element real array C DIMENSION array(20) DO j = 2, 20, 2 array(j) = 12.0 END DO C C Perform a function 11 times C DO k = -30, -60, -3 int = j / 3 isb = -9 - k array(isb) = MyFunc (int) END DO
The following shows the final value of a DO variable (in this case 11):
DO j = 1, 10 WRITE (*, '(I5)') j END DO WRITE (*, '(I5)') j