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 />

2.5 Statement Label Assignment (ASSIGN) Statement<br />

<br />

ASSIGN s TO i<br />

where:<br />

s<br />

i<br />

is a statement label<br />

is an integer variable name<br />

The statement label s is assigned to the integer variable i. The statement label must appear in the same<br />

program unit as the ASSIGN statement. The statement label must be that of an executable statement or a<br />

FORMAT statement.<br />

After a statement label has been assigned to an integer variable, that variable may only be used in an<br />

assigned GO TO statement or as a format identifier in an input/output statement. The integer variable must<br />

not be used in any other way (e.g., in an arithmetic expression). It may, however, be redefined with another<br />

statement label using the ASSIGN statement or it may be assigned an integer value (e.g., in an arithmetic<br />

assignment statement).<br />

Example:<br />

INTEGER RET<br />

X = 0.0<br />

ASSIGN 100 TO RET<br />

GO TO 3000<br />

100 X = X + 1<br />

ASSIGN 110 TO RET<br />

GO TO 3000<br />

110 X = X + 1<br />

.<br />

.<br />

.<br />

* Print both X and its square root<br />

3000 Y = SQRT( X )<br />

PRINT *, X, Y<br />

GO TO RET<br />

In the above example, we illustrate the use of the ASSIGN statement and the assigned GO TO statement to<br />

implement a "local subroutine" in a program unit. A sequence of often-used code can be "called" using the<br />

unconditional GO TO statement and "return" is accomplished using the assigned GO TO statement. Care<br />

must be exercised to properly assign the return label value.<br />

Example:<br />

IF( FIRST )THEN<br />

ASSIGN 100 TO LFRMT<br />

ELSE<br />

ASSIGN 200 TO LFRMT<br />

END IF<br />

WRITE( UNIT=5, FMT=LFRMT) X, Y, Z<br />

100 FORMAT(1X,3F10.5)<br />

200 FORMAT(1X,3E15.7)<br />

16 Statement Label Assignment (ASSIGN) Statement

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

Saved successfully!

Ooh no, something went wrong!