There are sixteen control statements:
The CALL and RETURN statements are described in Section 15.
GO TO s
where s is the statement label of an executable statement that appears in the same program unit as the unconditional GO TO statement.
Execution of an unconditional GO TO statement causes a transfer of control so that the statement identified by the statement label is executed next.
GO TO (s [,s]...) i
where:
Execution of a computed GO TO statement causes evaluation of the expression i. The evaluation of i is followed by a transfer of control so that the statement identified by the ith statement label in the list of statement labels is executed next, provided that 1 <= i <= n, where n is the number of statement labels in the list of statement labels. If i<1 or i>n, the execution sequence continues as though a CONTINUE statement were executed.
GO TO i [ (s [,s]...)]
where:
At the time of execution of an assigned GO TO statement, the variable i must be defined with the value of a statement label of an executable statement that appears in the same program unit. Note that the variable may be defined with a statement label value only by an ASSIGN statement (10.3) in the same program unit as the assigned GO TO statement. The execution of the assigned GO TO statement causes a transfer of control so that the statement identified by that statement label is executed next.
If the parenthesized list is present, the statement label assigned to i must be one of the statement labels in the list.
IF (e) s1, s2, s3
where:
Execution of an arithmetic IF statement causes evaluation of the expression e followed by a transfer of control. The statement identified by s1, s2, or s3 is executed next as the value of e is less than zero, equal to zero, or greater than zero, respectively.
IF (e) st
where:
Execution of a logical IF statement causes evaluation of the expression e. If the value of e is true, statement st is executed. If the value of e is false, statement st is not executed and the execution sequence continues as though a CONTINUE statement were executed.
Note that the execution of a function reference in the expression e of a logical IF statement is permitted to affect entities in the statement st.
The form of a block IF statement is:
IF (e) THEN
where e is a logical expression.
n1 - n2
where n1 is the number of block IF statements from the beginning of the program unit up to and including s, and n2 is the number of END IF statements in the program unit up to but not including s.
The IF-level of every statement must be zero or positive. The IF-level of each block IF, ELSE IF, ELSE, and END IF statement must be positive. The IF-level of the END statement of each program unit must be zero.
Transfer of control into an IF-block from outside the IF-block is prohibited.
If the execution of the last statement in the IF-block does not result in a transfer of control, control is transferred to the next END IF statement that has the same IF-level as the block IF statement that precedes the IF-block.
ELSE IF (e) THEN
where e is a logical expression.
Transfer of control into an ELSE IF-block from outside the ELSE IF-block is prohibited. The statement label, if any, of the ELSE IF statement must not be referenced by any statement.
If execution of the last statement in the ELSE IF-block does not result in a transfer of control, control is transferred to the next END IF statement that has the same IF-level as the ELSE IF statement that precedes the ELSE IF-block.
ELSE
An END IF statement of the same IF-level as the ELSE statement must appear before the appearance of an ELSE IF or ELSE statement of the same IF-level.
Transfer of control into an ELSE-block from outside the ELSE-block is prohibited. The statement label, if any, of an ELSE statement must not be referenced by any statement.
END IF
Execution of an END IF statement has no effect.
For each block IF statement there must be a corresponding END IF statement in the same program unit. A corresponding END IF statement is the next END IF statement that has the same IF-level as the block IF statement.
The form of a DO statement is:
DO s i = e1, e2 [,e3]
where:
The terminal statement of a DO-loop must not be an unconditional GO TO, assigned GO TO, arithmetic IF, block IF, ELSE IF, ELSE, END IF, RETURN, STOP, END, or DO statement. If the terminal statement of a DO-loop is a logical IF statement, it may contain any executable statement except a DO, block IF, ELSE IF, ELSE, END IF, END, or another logical IF statement.
If a DO statement appears within the range of a DO-loop, the range of the DO-loop specified by that DO statement must be contained entirely within the range of the outer DO-loop. More than one DO-loop may have the same terminal statement.
If a DO statement appears within an IF-block, ELSE IF-block, or ELSE-block, the range of that DO-loop must be contained entirely within that IF-block, ELSE IF-block, or ELSE-block, respectively.
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.
Once active, the DO-loop becomes inactive only when:
Execution of a function reference or CALL statement that appears in the range of a DO-loop does not cause the DO-loop to become inactive, except when control is returned by means of an alternate return specifier in a CALL statement to a statement that is not in the range of the DO-loop.
When a DO-loop becomes inactive, the DO-variable of the DO-loop retains its last defined value.
At the completion of execution of the DO statement, loop control processing begins.
For example:
N=0
DO 100 I=1,10
J=I
DO 100 K=1,5
L=K
100 N=N+1
101 CONTINUE
After execution of these statements and at the execution of the CONTINUE statement, I=11, J=10, K=6, L=5, and N=50.
Also consider the following example:
N=0
DO 200=I=1,10
J=I
DO 200 K=5,1
L=K
200 N=N+1
201 CONTINUE
After execution of these statements and at the execution of the CONTINUE statement, I=11, J=10, K=5, and N=0. L is not defined by these statements.
CONTINUE
Execution of a CONTINUE statement has no effect.
If the CONTINUE statement is the terminal statement of a DO-loop, the next statement executed depends on the result of the DO-loop incrementation processing (11.10.7).
STOP [n]
where n is a string of not more than five digits, or is a character constant.
Execution of a STOP statement causes termination of execution of the executable program. At the time of termination, the digit string or character constant is accessible.
PAUSE [n]
where n is a string of not more than five digits, or is a character constant.
Execution of a PAUSE statement causes a cessation of execution of the executable program. Execution must be resumable. At the time of cessation of execution, the digit string or character constant is accessible. Resumption of execution is not under control of the program. If execution is resumed, the execution sequence continues as though a CONTINUE statement were executed.
The form of an END statement is:
END
An END statement is written only in columns 7 through 72 of an initial line. An END statement must not be continued. No other statement in a program unit may have an initial line that appears to be an END statement.
The last line of every program unit must be an END statement.