Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fortran nested loops with one continue

I'm rewriting some legacy code and came across this:

  DO 4 I=1,N
   ...
  DO 4 J=1,N
   ...
4 CONTINUE

There appears to be only one CONTINUE for these two loops. Is it equivalent to this Java code?

for (int i=0; i<n; i++) {
    ...
    for (int j=0; j<n; j++) {
        ...
    }
}
like image 903
bcoughlan Avatar asked Sep 01 '11 17:09

bcoughlan


1 Answers

I think you are correct as to what it is equivalent to. The

4 CONTINUE

is just a labeled marker for the spot where the loop ends. Using two CONTINUE statements, or even better yet using two ENDDO (if supported by your compiler) would have been much clearer.

This page http://www.math.hawaii.edu/lab/197/fortran/fort2.htm concurs, just search for "same continue".

One detail though is that I don't think your loop variable start and end values are the same in your Java code as in the Fortran code.

like image 115
hatchet - done with SOverflow Avatar answered Oct 09 '22 10:10

hatchet - done with SOverflow