Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP Fortran Compiler for HP-UX: HP Fortran Programmer's Reference > Chapter 10 HP Fortran statements

CYCLE

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

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:

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© Hewlett-Packard Development Company, L.P.