12

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"?

yu_ominae
  • 2,975
  • 6
  • 39
  • 76

1 Answers1

12

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.

milancurcic
  • 6,202
  • 2
  • 34
  • 47
  • Thanks. Just to be absolutely clear on this, the GOTO 1301 statements will actually continue execution of the loop until the condition for termination of the loop is satisfied? – yu_ominae Jan 05 '12 at 06:38
  • Yes. Your GOTO 1301 takes you to 1301 CONTINUE, which will reiterate until the termination of the loop. – milancurcic Jan 05 '12 at 06:40