next up previous contents
Next: Named and Nested Loops Up: Control Flow Previous: Conditional Exit Loops

 

Conditional Cycle Loops

Situations often arise in practice when, for some exceptional reason, it is desirable to terminate a particular pass through a loop and continue immediately with the next repetition or cycle; this can be achieved in Fortran 90 by arranging that a CYCLE statement is executed at an appropriate point in the loop.

For example,

    DO
     DO ! here
      ...
      IF (a.GT.b) EXIT
      ...
      IF (a.EQ.b) CYCLE
      ...
     END DO
     IF (c.GT.d) EXIT
    END DO

Here CYCLE forces control to the innermost DO statement (the one that contains the CYCLE statement) and the loop begins a new iteration. (If a CYCLE statement is not followed by a construct name then the directive applies to the innermost loop at the current point in the code.) That is to say, in the example, the statement:

     IF (a.GT.b) CYCLE

if executed, will transfer control to the second DO statement (marked).

A CYCLE statement which is not within a loop is an error.


next up previous contents
Next: Named and Nested Loops Up: Control Flow Previous: Conditional Exit Loops

Adam Marshall ©University of Liverpool, 1996
Fri Dec 6 15:03:35 GMT 1996
Not for commercial use.