next up previous contents
Next: Initial Test (DO...WHILE) Loop Up: More on DO Loops Previous: Conditional CYCLE   Contents

Exit and Cycle with named loops

EXIT statement finishes the innermost loop; however, with named do loops, it can exit the indicated loop, regardless of its nesting level. Similarly, CYCLE outer cycles back to the outer loop, whereas a plain CYCLE would have cycled back to the inner loop.

outer: do i=1,9 
inner: do j=i,9 
  print*, "before: ",i, j
  if (j > 3) cycle outer ! go to outer: do
  print*, "before: ",i, j
  if (j > 6) exit outer ! go to outer: do
  print*, "after: ",i,j
end do inner 
end do outer

Adrian Sandu 2001-08-26