Statement Purpose

The continue statement is an odd statement in FORTRAN. It is an executable statement but it takes no action in the program. It's primarily used as a place holder to span gaps created between branches or loops and the rest of the program.

Examples of Use

The most common way in which the continue statement has been used in FORTRAN is as the last statement in a do loop. For instance, in the following example the program will execute every statement between the DO statement and CONTINUE labeled 1000 a to total of 100 times. After the specified number of loops, execution will continue at the next statement below the CONTINUE. Please note that the continue statement serves the exact same purpose in this example as an END DO statement does.
		Do 1000 i=1,100
			x = y**2+3i
	1000  continue
Another way in which the continue statement can be used is as an termination point for branching statements. In the following if construct, an unconditional go to statement is used to loop around the value of y that would be computed if x was greater than five. The continue is then used as the target for that go to statement. The continue statement then serves as a bridge between the branching structure and the rest of the program and allows significant flexibility in changing coding before and after the branch destination.
    		      if ( go to 110
     		   go to 120
		 110   y=(x=5.)**2
		 120  continue
Even though conditional structures written like this are still valid FORTRAN, it is recommended that you avoid writing them. This is an archaic form of FORTRAN that was used before the advent of the block IF structure for looping. The block if structure is neater and nicer to use, so it is the preferred construct in this case. In fact the combination of the END DO statement, Block IF, and CASE structures make CONTINUE far less useful than it was in older FORTRAN programs.

For additional examples and information see

lecture eleven and fifteen

examples: fall1.f and curvefit.f

Up one level / Home

Written by Jason Wehr : and Maintained by John Mahaffy :