Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
New Contributor I
12 Views

Q about Do Loops

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

     enddo

   enddo

enddo

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
Highlighted
Valued Contributor III
12 Views

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:

CYCLE

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

CYCLE [name]

name

(Optional) Is the name of the DO construct.

Description

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.

 

0 Kudos
Highlighted
Black Belt
12 Views

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

0 Kudos