CYCLE

Purpose

The CYCLE statement terminates the current execution cycle of a DO or DO WHILE construct that it belongs to.

Fortran 2008 begins The CYCLE statement completes the execution of the current iteration of the DO CONCURRENT construct that it belongs to.Fortran 2008 ends

Syntax

Read syntax diagramSkip visual syntax diagramCYCLEDO_construct_name
DO_construct_name
is the name of a DO, Fortran 2008 beginsDO CONCURRENTFortran 2008 ends, or DO WHILE construct.

Rules

The CYCLE statement is placed within a DO, Fortran 2008 beginsDO CONCURRENTFortran 2008 ends, or DO WHILE construct and belongs to the particular DO, Fortran 2008 beginsDO CONCURRENTFortran 2008 ends, or DO WHILE construct that is specified by DO_construct_name. If DO_construct_name is not specified, the CYCLE statement belongs to the DO, Fortran 2008 beginsDO CONCURRENTFortran 2008 ends, or DO WHILE construct that immediately surrounds it.

Fortran 2008 beginsA CYCLE statement must not be placed within a DO CONCURRENT construct if it belongs to an outer construct.Fortran 2008 ends

Execution of a CYCLE statement that belongs to a DO or DO WHILE construct only terminates the current execution cycle of the DO or DO WHILE construct. Any executable statements after the CYCLE statement, including any terminating labeled action statement, will not be executed. For DO constructs, program execution continues with incrementation processing, if any. For DO WHILE constructs, program execution continues with loop control processing.

Fortran 2008 beginsExecution of a CYCLE statement that belongs to a DO CONCURRENT construct completes the execution of the current iteration of the construct.Fortran 2008 ends

A CYCLE statement can have a statement label. However, it cannot be used as a labeled action statement that terminates a DO construct.

Examples

LOOP1: DO I = 1, 20
   N = N + 1
   IF (N > NMAX) CYCLE LOOP1          ! cycle to LOOP1

   LOOP2: DO WHILE (K==1)
      IF (K > KMAX) CYCLE             ! cycle to LOOP2
      K = K + 1
   END DO LOOP2

   LOOP3:  DO J = 1, 10
      N = N + 1
      IF (N > NMAX) CYCLE LOOP1       ! cycle to LOOP1
      CYCLE LOOP3                     ! cycle to LOOP3
   END DO LOOP3

END DO LOOP1
END

Related information