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.

Program Structure Control Statements<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’ )QUIT : 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 QUIT 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 QUIT : RDREC statement will cause control to be passed to the PRINT<br />

statement after the END LOOP statement.<br />

9.14 EXIT<br />

EXIT<br />

[ : block-label]<br />

The EXIT statement is used to transfer control:<br />

1. from within a loop (DO, DO WHILE, WHILE or LOOP) to the statement following the loop,<br />

2. from within a GUESS or ADMIT block to the statement following the ENDGUESS statement, or<br />

3. from within a remote block to the statement following the EXECUTE statement that invoked the<br />

remote block.<br />

When transferring out of a loop, control is passed to the statement following the END DO, END WHILE,<br />

END LOOP or UNTIL statement.<br />

When transferring out of a GUESS block, control is passed to the statement after the corresponding END<br />

GUESS statement.<br />

When transferring out of a REMOTE-block, control passes to the statement following the EXECUTE<br />

statement that invoked the REMOTE-block.<br />

If no block label is specified in the EXIT statement, control is transferred from the immediately enclosing<br />

structure. If several structures or DO-loops are nested, it is possible to exit from any one of them by<br />

specifying the block label of the corresponding block structure.<br />

The EXIT statement is most commonly used as the statement in a logical IF or AT END statement but<br />

may also be used to cause an unconditional transfer of control. (The AT END statement is described in a<br />

subsequent section).<br />

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

EXIT 209

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

Saved successfully!

Ooh no, something went wrong!