FORTRAN Reference Manual

Statements
FORTRAN Reference Manual528615-001
7-56
Unconditional GO TO
ivar
is an integer variable previously assigned a label value in an ASSIGN statement.
Considerations
A GO TO statement must not transfer control to a statement within a DO loop.
Unconditional GO TO
An unconditional GO TO statement transfers program control directly to the statement
whose label is specified by the GO TO statement. In the following example, control
passes from the GO TO statement to the PRINT statement labeled 300. Intervening
statements, if any, are skipped:
GO TO 300
.
300 PRINT *, answer
Computed GO TO
A computed GO TO statement consists of the word GO TO followed by a comma
separated list of labels enclosed in parentheses, followed by an arithmetic expression.
Each label must be associated with an executable statement. FORTRAN evaluates the
expression and transfers control to the statement whose label’s position in the list of
labels is equal to the value of the expression. The index of the first label in the list is 1.
In the following example, FORTRAN evaluates the expression and truncates it, if
necessary, to an integer result:
GO TO (100, 200, 200, 300), k + 1
FORTRAN transfers control to statement 100 if k+1 equals 1, to statement 200 if k+1
equals 2 or k + 1 equals 3, and to statement 300 if k+1 equals 4.
If the value of the expression is less than one or greater than the number of labels in
the list, FORTRAN transfers control to the statement that follows the computed GO TO
statement.
Assigned GO TO
An assigned GO TO statement transfers control to the statement whose label was
assigned to ivar in an ASSIGN statement that was executed previously in the same
run of the program unit containing the assigned GO TO.
Before your program executes an assigned GO TO statement, you must assign a label
to ivar using an ASSIGN statement. The following example shows an ASSIGN