I have a Fortran77 snippet that looks like this:
DO 1301 N=NMLK-2,2,-1
Some code...
IF(NB1(N).EQ.50) GOTO 1300
Some code...
IF(BS(N).EQ.0.0) GOTO 1301
some code...
GOTO 1301
1300 NW(M)=NB1(N)
Some code...
1301 CONTINUE
When this hits the GOTO 1301 statement, does this jump to the next iteration of the loop or does it exit the loop? As far as I understand the return keyword does nothing, so I assume that this will just exit the loop and continue code execution from label 1301, is that correct?
I am translating this to C# and am wondering if this is equivalent:
for (N = NMLK; N >= 2; N--)
{
Some code...
if (NB1[N] == 50)
goto l1300;
Some code...
if (BS[N] == 0)
return;
Some code...
return;
l1300:
NW[M] = NB1[N];
Some code...
}
or if I should have "continue" instead of "return"?
The CONTINUE statement is often used as a place to hang a statement label, usually it is the end of a DO loop. The CONTINUE statement is used primarily as a convenient point for placing a statement label, particularly as the terminal statement in a DO loop. Execution of a CONTINUE statement has no effect.
Just like an IF-THEN-ELSE-END IF can contain another IF-THEN-ELSE-END IF (see nested IF for the details), a DO-loop can contain other DO-loops in its body. The body of the contained DO-loop, usually referred to as the nested DO-loop, must be completely inside the containing DO-loop.
Fortran 77 has only one loop construct, called the do-loop. The do-loop corresponds to what is known as a for-loop in other languages. Other loop constructs have to be built using the if and goto statements.
Yes, the GOTO 1301
statement makes the program jump to next iteration.
The DO label
, label CONTINUE
is an obsolete way to write a more contemporary DO ENDDO
block. In this case the loop will iterate over variables specified on the DO line, and label CONTINUE
line serves as an "ENDDO
" placeholder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With