HP Fortran Programmer's Reference (September 2007)

Execution control
Flow control statements
Chapter 6 149
.
GOTO int_label
.
.
.
20 ...
Computed GO TO statement
The computed GO TO statement transfers control to one of several labeled statements, as
determined by the value of an arithmetic expression.
Syntax
GO TO (
label-list
) [ , ]
integer-expression
Execution logic
1.
integer-expression
is evaluated.
2. The resulting integer value (the index) specifies the ordinal position of the label that is
selected from
label-list
.
3. Control transfers to the executable statement with the selected label. If the value of the
index is less than 1 or greater than the number of labels in
label-list
, the computed GO
TO statement has no effect, and control passes to the next executable statement in the
program.
Example
DO
PRINT *, ”Enter a number 1-3: ”
READ *, k
GO TO (20, 30, 40) k
PRINT *, ”Number out of range.”
EXIT
20 i = 20
GO TO 100
30 i = 30
GO TO 100
40 i = 40
100 print *, i
END DO
Unconditional GO TO statement
The unconditional GO TO statement transfers control to the statement with the specified label.
Syntax