HP Fortran Programmer's Reference (September 2007)

Execution control
Flow control statements
Chapter 6 147
triangular_num = triangular_num + i
10 CONTINUE
PRINT *, triangular_num
CYCLE statement
The CYCLE statement interrupts execution of the current iteration of a DO loop.
Syntax
CYCLE [
do-construct-name
]
Execution logic
1. The current iteration of the enclosing DO loop terminates. Any statements following the
CYCLE statement do not execute.
2. If
do-construct-name
is specified, the iteration count for the named DO loop decrements.
If
do-construct-name
is not specified, the iteration count for the immediately enclosing
DO loop decrements.
3. If the iteration count is nonzero, execution resumes at the start of the statement block in
the named (or enclosing) DO loop. If it is zero, the relevant DO loop becomes inactive.
Example
LOGICAL :: even
INTEGER :: number
loop: DO i = 1, 10
PRINT *, ”Enter an integer: ”
READ *, number
IF (number == 0) THEN
PRINT *, ”Must be nonzero.”
CYCLE loop
END IF
even = (MOD(number, 2) == 0)
IF (even) THEN
PRINT *, ”Even”
ELSE
PRINT *, ”Odd”
END IF
END DO loop
EXIT statement
The EXIT statement terminates a DO loop. If it specifies the name of a DO loop within a nest of
DO loops, the EXIT statement terminates all loops by which it is enclosed, up to and including
the named DO loop.