24.11.2014 Views

Open Watcom FORTRAN 77 Language Reference

Open Watcom FORTRAN 77 Language Reference

Open Watcom FORTRAN 77 Language Reference

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Language</strong> <strong>Reference</strong><br />

The next example demonstrates the use of a GO TO statement to control execution of all or part of a<br />

DO-loop.<br />

Example:<br />

I = 1<br />

DO WHILE( I .LE. 3 )<br />

J = 1<br />

DO WHILE( J .LE. 5 )<br />

PRINT *, ’INNER LOOP - J=’, J<br />

IF( J .LE. 3 )GO TO 20<br />

PRINT *, ’J > 3’<br />

20 END DO<br />

PRINT *, ’OUTER LOOP - J=’, J<br />

END DO<br />

A result of this example is that the character string J > 3 is printed 6 times (i.e., twice for each iteration<br />

of the outer loop). Of course there is a much better way of coding this algorithm using the IF-END IF<br />

construct. The example is included to illustrate the behaviour of transfers of control to an END DO<br />

statement. The following example is an equivalent algorithm to the one above but the intent is much<br />

clearer.<br />

Example:<br />

I = 1<br />

DO WHILE( I .LE. 3 )<br />

J = 1<br />

DO WHILE( J .LE. 5 )<br />

PRINT *, ’INNER LOOP - J=’, J<br />

IF( J .GT. 3 )THEN<br />

PRINT *, ’J > 3’<br />

END IF<br />

END DO<br />

PRINT *, ’OUTER LOOP - J=’, J<br />

END DO<br />

9.6 LOOP - END LOOP<br />

LOOP [: block-label]<br />

statement(s)<br />

END LOOP<br />

This extension to <strong>FORTRAN</strong> <strong>77</strong> causes the statements between the LOOP and END LOOP statements to be<br />

repeated until control is transferred out of the loop, usually by an EXIT or QUIT statement. An optional<br />

block label may be specified (see the CYCLE, EXIT or QUIT statement for more information). An<br />

example follows:<br />

198 LOOP - END LOOP

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!