HP Fortran Programmer's Reference (September 2007)

Execution control
Flow control statements
Chapter 6150
GO TO
label
Execution logic
Control transfers to the statement at
label
.
Example
Older, “dusty-deck” Fortran programs often combine the GO TO statement with the logical IF
statement to form a kind of leap-frog logic, as in the following:
IF ( num1 /= num2) GO TO 10
PRINT *, ”num1 and num2 are equal.”
GO TO 30
10 IF ( num1 > num2 ) GO TO 20
PRINT *, ”num1 is smaller than num2.”
GO TO 30
20 PRINT *, ”num1 is greater than num2.”
30 CONTINUE
Arithmetic IF statement
The arithmetic IF transfers control to one of three labeled statements, as determined by the
value of an arithmetic expression.
Syntax
IF (
arithmetic-expression
)
label1
,
label2
,
label3
Execution logic
1.
arithmetic-expression
is evaluated.
2. If the resulting value is negative, control transfers to the statement at
label1
.
3. If the resulting value is 0, control transfers to the statement at
label2
.
4. If the resulting value is positive, control transfers to the statement at
label3
.
Example
As shown in this example, two or more labels in the label list can be the same.
i = MOD(total, 3) + 1
IF ( i ) 10, 20, 10
Logical IF statement
The logical IF statement executes a single statement, conditional upon the value of a logical
expression. The statement it executes must not be:
A statement used to begin a construct