Why and how to continue?

I have the following lines of code (reduced, since 90% is irrelevant to my question)…

        if(ifirst .eq. 0) then

        if(nrec .ne. 0) then
            if(CorM .lt. zMmin) then
                <SOME CALCULATIONS HERE>
            if(CorM.lt.zM(N)) then
 88   continue   !< restart >!

        call start(istmod)

        if(irst.gt.0) then

It’s that continue that piques my curiousity.
Line 286 (the 88 label is on line 128) states…

go to 88

So, obviously this is a jump to the label but why the continue statement?
Doesn’t the program simply jump to the 88 label and continue execution from that line onwards anyway?

Could I not simply replace it with…

 88   call start(istmod)

        if(irst.gt.0) then

I’m working through the code and will endeavour to replace this jump with a loop of some kind but, for now, I just need to work out the flow of the program overall.

Am I correct? Flow continues to the next line after the continue statement? But that this would happen anyway; even if I replaced the continue instruction with the next instruction after it?

Suppose that I felt that I might want to add some diagnostic PRINT statements such as

PRINT *,' About to call START'

between statement no. 88 and the CALL statement. I could punch one or more cards with those diagnostic statements, slip them into the Fortran source deck between the 88 CONTINUE and the CALL cards and, when finished with diagnosing bugs, remove those cards. Now, limited to punched cards for program source, if I had followed your suggestion, where would I be?

So, the continue makes sense when we used Fortran on punchcards (since it is easier to insert and remove lines after the label) but, then, there is no purpose for maintaining this when dealing with IDEs. :slight_smile:
I do love the historical referencing of Fortran; sad to lose it but, seriously, trying to claw every cycle I can back! Ha ha ha!

Thank you so much!

Card punches probably became obsolete before you were born, but thanks for shedding some tears on my behalf!

A modern compiler is most likely to put out the same object code regardless of whether or not the CONTINUE statement is used. The CONTINUE statement is just syntactic salt, and there won’t be any lost cycles because of it.

I did experience punchcards, but I was very young. I also have several of them around, since I use them to educate the students I have on where we are and how we got here.

I’ll probably remove it purely for the clarity of the code then. I’ll also look to see if I can replace the jump (go to) with a loop of some kind - feels odd using goto statements again; a little ‘unclean’! Hahahaha!

There are utilities (stand-alone or part of a compiler) that can take old Fortran “spaghetti” code and output well structured code with dead code removed and declarations added. Examples are SPAG (stand-alone) and NAG Fortran (compiler with clean-up option). Some of these may even have a dedicated option to remove CONTINUE statements.

CONTINUE statements were useful in simplifying nested DO loops with shared termination in Fortran IV code.

I need to work out how this code is working, so tidying it up myself is helping enormously. :slight_smile:

I also plan on developing it into Fortran90 (free form) code but first I need to see how everything fits together and the logic behind it.

1 Like

@garynewport ,

This is going by hearsay and style guides, etc. from the time period where the notions of structured programming in FORTRAN codes were different than now, meaning relative to what has been introduced in the language starting with Fortran 90 and enhanced thru’ Fortran 95, 2003, 2008, and now 2018 revisions. So caveat emptor!

But the thought process then appeared to have been to employ the CONTINUE statement with a numeric label and to include comments in the following lines to explain the workflow, see a hypothetical example below.

Given such thinking, it was common to come across CONTINUE statements with a statement label rather than actual statements with such a label.

     IF ( ABS(ERROR) .GE. TOL ) GO TO 88
     WRITE(1234, ..) .., ERROR, ..
     METHOD = ..
     GO TO 55
1 Like

There are tools to automatically convert fixed to free source form, listed here. I suggest first converting to free format, verifying that the code gives the same results, and then trying to understand and improve it. Code in free format is easier to read, since having a character in a certain column does not change the meaning of the code.

I remember from my student days a poster with 10 commandments for FORTRAN programmers (those were simple times, I guess). One of the commandments was:

Let every DO-loop has its own CONTINUE

While I hardly ever use CONTINUE anymore, I have kept this in mind as a way to clarify the role of the numerical label.

This is mandated by the Fortran 2018 standard. For

integer :: i,j
do 10 i=1,5
   do 10 j=1,3
10 continue

gfortran -std=f2018 docon.f90 says


    2 | do 10 i=1,5
      |           1
Warning: Fortran 2018 obsolescent feature: Labeled DO statement at (1)

    3 |    do 10 j=1,3
      |              1
Error: Fortran 2018 deleted feature: Shared DO termination label 10 at (1)