Control statements may be used to control the execution
sequence.
There are sixteen control statements:
- Unconditional GO TO
- Computed GO TO
- Assigned GO TO
- Arithmetic IF
- Logical IF
- Block IF
- ELSE IF
- ELSE
- END IF
- DO
- CONTINUE
- STOP
- PAUSE
- END
- CALL
- RETURN
The CALL and RETURN statements are described in Section
15.
The form of an unconditional GO TO statement is:
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.
The form of a computed GO TO statement is:
GO TO (s [,s]...) i
- where:
i
is an integer expression
-
s
is the statement label of an executable statement
that appears in the same program unit as the
computed GO TO statement. The same statement
label may appear more than once in the same
computed GO TO statement.
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.
The form of an assigned GO TO statement is:
GO TO i [ (s [,s]...)]
- where:
i
is an integer variable name
-
s
is the statement label of an executable statement
that appears in the same program unit as the
assigned GO TO statement. The same statement
label may appear more than once in the same
assigned GO TO statement.
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.
The form of an arithmetic IF statement is:
IF (e) s , s , s
1 2 3
- where:
e
is an integer, real, or double precision
expression
-
s , s , and s
1 2 3
are each the statement label of an
executable statement that appears in the same
program unit as the arithmetic IF statement.
The same statement label may appear more than
once in the same arithmetic IF statement.
Execution of an arithmetic IF statement causes evaluation
of the expression
e
followed by a transfer of control.
The statement identified by
s , s , or s
1 2 3
is executed next
as the value of
e
is less than zero, equal to zero, or
greater than zero, respectively.
The form of a logical IF statement is:
IF (e) st
- where:
e
is a logical expression
-
st
is any executable statement except a DO,
block IF, ELSE IF, ELSE, END IF, END, or another
logical IF statement
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 block IF statement is used with the END IF statement
and, optionally, the ELSE IF and ELSE statements to control
the execution sequence.
The form of a block IF statement is:
IF (e) THEN
where
e
is a logical expression.
The
IF-level
of a statement
s
is
n - n
1 2
where
n
1
is the number of block IF statements from the
beginning of the program unit up to and including
s
, and
n
2
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.
An
IF-block
consists of all of the executable statements
that appear following
the block IF statement up to, but not including, the
next ELSE IF, ELSE, or END IF statement that has the same
IF-level as the block IF statement. An IF-block may be
empty.
Execution of a block IF statement causes evaluation of the
expression
e
. If the value of
e
is true, normal execution
sequence continues with the first statement of the IF-block.
If the value of
e
is true and
the IF-block is empty, control is transferred
to the next END IF statement that has the same IF-level
as the block IF statement. If the value of
e
is false,
control is transferred to the next ELSE IF, ELSE, or END IF
statement that has the same IF-level as the block IF
statement.
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.
The form of an ELSE IF statement is:
ELSE IF (e) THEN
where
e
is a logical expression.
An
ELSE IF-block
consists of all of the executable
statements that appear following the ELSE IF statement up to, but not
including, the next ELSE IF, ELSE, or END IF statement
that has the same IF-level as the ELSE IF statement. An
ELSE IF-block may be empty.
Execution of an ELSE IF statement causes evaluation of the
expression
e
. If the value of
e
is true, normal execution
sequence continues with the first statement of the ELSE IF-block.
If the value of
e
is true and
the ELSE IF-block is empty, control is
transferred to the next END IF statement that has the same
IF-level as the ELSE IF statement. If the value of
e
is
false, control is transferred to the next ELSE IF, ELSE,
or END IF statement that has the same IF-level as the
ELSE IF statement.
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.
The form of an ELSE statement is:
ELSE
An
ELSE-block
consists of all of the executable statements
that appear following
the ELSE statement up to, but not including, the
next END IF statement that has the same IF-level as the
ELSE statement. An ELSE-block may be empty.
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.
Execution of an ELSE statement has no effect.
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.
The form of an END IF statement is:
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.
A DO statement is used to specify a loop, called a
DO-loop.
The form of a DO statement is:
DO s i = e , e , [,e ]
1 2 3
- where:
s
is the statement label of an executable
statement. The statement identified by
s
, called
the
terminal statement
of the DO-loop, must
follow the DO statement in the sequence of
statements within the same program
unit as the DO statement.
-
i
is the name of an integer, real, or double
precision variable, called the
DO-variable
-
e , e , and e
1 2 3
are each an integer, real, or double
precision expression
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.
The
range of a DO-loop
consists of all of the executable statements
that appear following
the DO statement that specifies the DO-loop, up to and
including the terminal statement of the DO-loop.
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.
A DO-loop is either active or inactive. Initially inactive,
a DO-loop becomes active only when its DO statement is
executed.
Once active, the DO-loop becomes inactive only when:
- its iteration count is tested (
11.10.4)
and determined to be zero,
- a RETURN statement is executed within its range,
- control is transferred to a statement
that is in the same program unit and is outside the
range of the DO-loop, or
- any STOP statement in the executable program is
executed, or execution is terminated for any other reason
(
12.6).
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.
The effect of executing a DO statement is to perform the
following steps in sequence:
- The
initial parameter
m
1
,
the
terminal parameter
m
2
,
and the
incrementation parameter
m
3
are established by evaluating
e
1
,
e
2
, and
e
3
,
respectively, including, if necessary, conversion
to the type of the DO-variable according to the
rules for arithmetic conversion (Table 4). If
e
3
does not appear,
m
3
has a value of one.
m
3
must
not have a value of zero.
- The DO-variable becomes defined with the value of
the initial parameter
m
1
.
- The iteration count is established and is the value
of the expression
-
MAX( INT( (m - m + m )/m ), 0)
2 1 3 3
- Notethat the iteration count is zero whenever:
-
m > m and m > 0, or
1 2 3
-
m < m and m < 0.
1 2 3
At the completion of execution of the DO statement, loop
control processing begins.
Loop control processing determines if further execution
of the range of the DO-loop is required. The iteration
count is tested. If it is not zero, execution of the first
statement in the range of the DO-loop begins. If the
iteration count is zero, the DO-loop becomes inactive.
If, as a result, all of the DO-loops sharing the terminal
statement of this DO-loop are inactive, normal execution
continues with execution of the next executable statement
following the terminal statement. However, if some of the
DO-loops sharing the terminal statement are active,
execution continues with incrementation processing, as
described in
11.10.7.
Statements in the range of a DO-loop are executed until
the terminal statement is reached. Except by the
incrementation described in
11.10.7, the DO-variable of
the DO-loop may neither be redefined nor become undefined
during execution of the range of the DO-loop.
Execution of the terminal statement occurs as a result of
the normal execution sequence or as a result of transfer
of control, subject to the restrictions in
11.10.8. Unless
execution of the terminal statement results in a transfer
of control, execution then continues with incrementation
processing, as described in
11.10.7.
Incrementation processing has the effect of the following
steps performed in sequence:
- The DO-variable, the iteration count, and the incrementation parameter
of the active DO-loop whose DO statement was most
recently executed, are selected for processing.
- The value of the DO-variable is incremented by the
value of the incrementation parameter
m
3
.
- The iteration count is decremented by one.
- Execution continues with loop control processing
(
11.10.4) of the same DO-loop whose iteration count
was decremented.
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
-
D0 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.
Transfer of control into the range of
a DO-loop from outside the range
is not permitted.
The form of a CONTINUE statement is:
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).
The form of a STOP statement is:
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.
The form of a PAUSE statement is:
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 END statement indicates the end of the sequence of
statements and comment lines of a program unit (
3.5). If
executed in a function or subroutine subprogram, it has the effect of a RETURN
statement (
15.8). If executed in a main program, it
terminates the execution of the executable program.
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.
[Contents] [Previous]
[Next] [Home]
NDP77
http://www.ndp77.net
webmaster MFA (main)
webmaster@ndp77.net