Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!

Q about Do Loops

New Contributor I

I have a situation where I need to execute DO Loops where the final statement is not an ENDDO.


So, if I do a CYCLE, will it skip that statement , or execute that as well?


Of course, if had more than one statement to be executed at the end of the loop, 

I would have to use a Go To instead.


Incidentally, does the compiler give us an upper limit regarding the depth of do loops inside each other ?

for example,

Do I1=1,10

  do I2=1,10

     do I3=1,10




Here, the depth is 3, but I came across a situation where the compiler gets confused when you have a depth much greater than that.

I had to solve the problem by moving the innermost statements into a separate routine.

0 Kudos
2 Replies
Honored Contributor I

I have a situation where I need to execute DO Loops where the final statement is not an ENDDO.

I don't get that, just insert and enddo problem solved. The is far clearer and more standard to always end loop on enddo and never to have a shared labelled statem,ent.

In answer to cycle:


Statement: Interrupts the current execution cycle of the innermost (or named) DO construct.

CYCLE [name]


(Optional) Is the name of the DO construct.


When a CYCLE statement is executed, the following occurs:

  1. The current execution cycle of the named (or innermost) DO construct is terminated.

    If a DO construct name is specified, the CYCLE statement must be within the range of that construct.

  2. The iteration count (if any) is decremented by 1.

  3. The DO variable (if any) is incremented by the value of the increment parameter (if any).

  4. A new iteration cycle of the DO construct begins.

Any executable statements following the CYCLE statement (including a labeled terminal statement) are not executed.

A CYCLE statement can be labeled, but it cannot be used to terminate a DO construct.

Execution of a CYCLE statement that belongs to a DO CONCURRENT construct completes execution of that iteration of the construct.


Black Belt

The limit on the nesting of the various executable block constructs is specified as 512 in the documentation for the current release.