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>FORTRAN</strong> Statements<br />

2.48 Assigned GO TO Statement<br />

<br />

GO TO i [[,] (s [,s]...)]<br />

where:<br />

i<br />

s<br />

is an integer variable name.<br />

is the statement label of an executable statement that appears in the same program unit as the<br />

assigned GO TO statement.<br />

The variable i must be defined with the value of a statement label of an executable statement that appears<br />

in the same program unit (see the ASSIGN statement). The execution of the assigned GO TO statement<br />

causes a transfer of control to the statement that is identified by that label.<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 />

If a list of statement labels is present then the statement label assigned to i must be in the list. If it is not in<br />

the list, an error will occur when the assigned GO TO statement is executed. Unlike the computed GO TO<br />

statement, execution does not continue with the next statement. This is demonstrated by the following<br />

example. Note that the "," preceding the statement label list is optional.<br />

Example:<br />

Assigned GO TO Statement 81

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

Saved successfully!

Ooh no, something went wrong!