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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

Example:<br />

LOOP<br />

READ *, X<br />

AT END, EXIT<br />

PRINT *, X<br />

END LOOP<br />

The above statements read and print values until an end of file occurs. At that point control is passed to the<br />

EXIT statement, as specified by the AT END statement. The EXIT statement causes control to continue<br />

with the statement after the END LOOP statement.<br />

Example:<br />

CHARACTER RECORD(80)<br />

LOOP : RDREC<br />

READ(5,100) RECORD<br />

AT END, STOP<br />

DO I = 1, 80<br />

IF( RECORD(I) .LT. ’0’<br />

+ .OR. RECORD(I) .GT. ’9’ )EXIT : RDREC<br />

END DO<br />

WRITE(6,101) RECORD<br />

END LOOP<br />

PRINT *, ’INVALID RECORD’<br />

The above example reads in records and verifies that they contain only numeric data. The EXIT statement<br />

is within two levels of nesting: the DO-loop and the LOOP-END LOOP structure. If a non-numeric<br />

character is found, the EXIT : RDREC statement will cause control to be passed to the PRINT<br />

statement after the END LOOP statement.<br />

9.15 CYCLE<br />

CYCLE<br />

[ : block-label]<br />

The CYCLE statement is used to cause a transfer of control from within a loop to the terminal statement of a<br />

corresponding DO, DO WHILE, WHILE or LOOP statement. If block-label is present then control is<br />

transferred to the terminal statement of the block identified by that block label.<br />

If no block label is specified in the CYCLE statement, control is transferred to the terminal statement of the<br />

immediately enclosing loop structure. If several loop structures are nested, it is possible to cycle to the<br />

terminal statement of any one of them by specifying the block label of the corresponding block structure.<br />

The CYCLE statement is most commonly used as the statement in a logical IF statement but may also be<br />

used to cause an unconditional transfer of control.<br />

Examples of the CYCLE statement with and without a block label follow.<br />

210 CYCLE

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

Saved successfully!

Ooh no, something went wrong!