Interrupts current iteration of a DO loop.
Syntax
CYCLE [ do-construct-name ] |
- do-construct-name
is the name of a DO construct that must contain this CYCLE statement.
Description
The CYCLE statement is used to control the execution of
a DO loop. When it executes, it interrupts a currently
executing loop iteration and passes control to the next iteration, making
the appropriate adjustments to the loop index. It may be used with
either the DO construct or the FORTRAN 77-style DO loop.
A CYCLE statement belongs to a particular DO loop. If do-construct-name is not given, the CYCLE statement resumes the immediately enclosing DO loop. If do-construct-name is given, the CYCLE statement resumes an enclosing named DO loop with the same name.
Examples
The following example uses the CYCLE statement to control a bubble sort:
LOGICAL :: swap INTEGER :: i, j outer: DO i = 1, n-1 swap = .FALSE. inner: DO j = n, i+1, -1 IF (a(j) >= a(j-1)) CYCLE inner swap = .TRUE. atmp = a(j) a(j) = a(j-1) a(j-1) = atmp END DO inner IF (.NOT. swap) EXIT outer END DO outer |
Related statements
DO and EXIT
Related concepts
For related information, see the following: