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.

Program Structure Control Statements<br />

Example:<br />

LOOP<br />

WRITE( UNIT=*, FMT=’(A)’ ) ’Enter a number’<br />

READ( UNIT=*, FMT=’(F10.4)’, IOSTAT=IOS ) X<br />

IF( IOS .NE. 0 ) CYCLE<br />

IF( X .LT. 0 ) EXIT<br />

PRINT *, X, SQRT( X )<br />

END LOOP<br />

The above statements read and print values until a negative integer value is entered. If an input error<br />

occurs, the input operation (READ) is retried using the CYCLE statement. The CYCLE statement causes<br />

control to resume at the END LOOP statement which then immediately transfers control to the statement<br />

following the 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’ )THEN<br />

PRINT *, ’INVALID RECORD’<br />

CYCLE : RDREC<br />

ENDIF<br />

END DO<br />

WRITE(6,101) RECORD<br />

END LOOP<br />

The above example reads in records and verifies that they contain only numeric data. If the record does<br />

not, the input operation is tried again. The CYCLE statement is within three levels of nesting: the IF, the<br />

DO-loop, and the LOOP-END LOOP structure. If a non-numeric character is found, the CYCLE :<br />

RDREC statement will cause control to be passed to the READ statement that follows the LOOP statement.<br />

9.16 AT END<br />

(READ statement)<br />

AT END DO [: block-label ]<br />

statement(s)<br />

END AT END<br />

or<br />

(READ statement)<br />

AT END, statement<br />

The AT END control statement, an extension to <strong>FORTRAN</strong> <strong>77</strong>, is an extension of the END= option of the<br />

<strong>FORTRAN</strong> READ statement for sequential files. It allows a statement or a block of code following the<br />

AT END 211

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

Saved successfully!

Ooh no, something went wrong!