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

the block is completed. A block started within a DO-loop must be terminated before the<br />

DO-loop is completed. Indenting the statements of each new block, as shown in the<br />

examples, is helpful in avoiding invalid nesting and helps to make the structure of the<br />

program visually obvious.<br />

(iii)<br />

The normal flow of control of the new programming constructs described earlier may be<br />

altered with standard <strong>FORTRAN</strong> control statements. For example, the program may exit<br />

from a block using a GO TO, STOP, RETURN or arithmetic IF statement. However, a<br />

block may not be entered in the middle through use of any control statement such as GO<br />

TO or the arithmetic IF.<br />

Consider the following example.<br />

Example:<br />

GO TO 20<br />

10 IF( X .GT. Y )THEN<br />

CALL REDUCE( X, Y )<br />

20 X = X - 1<br />

ELSE<br />

CALL SCALE( X )<br />

END IF<br />

This is an example of an illegal attempt to transfer execution into the middle of an IF-block.<br />

The statement X = X - 1 is contained within the IF-block and may only be transferred<br />

to from within the block.<br />

Example:<br />

IF( X .GT. Y )THEN<br />

20 CALL REDUCE( X, Y )<br />

X = X - 1<br />

IF( X .GT. 0 )GO TO 20<br />

ELSE<br />

CALL SCALE( X )<br />

END IF<br />

This last example demonstrates a legal transfer of control within an IF-block. However, we<br />

have seen better ways to express the loop with this IF-block.<br />

Example:<br />

IF( X .GT. Y )THEN<br />

LOOP<br />

CALL REDUCE( X, Y )<br />

X = X - 1<br />

UNTIL( X .LE. 0 )<br />

ELSE<br />

CALL SCALE( X )<br />

END IF<br />

(iv)<br />

(v)<br />

Many control structure statements cannot be branched to using a GO TO statement. For a<br />

list of these statements, see the section entitled "Classifying Statements" on page 9 in the<br />

chapter entitled "<strong>FORTRAN</strong> Statements"<br />

Many control structure statements cannot be the object statement of a logical IF statement,<br />

or be the last statement of a DO-loop. For a list of these statements, see the section entitled<br />

"Classifying Statements" on page 9 in the chapter entitled "<strong>FORTRAN</strong> Statements"<br />

Notes on Structured Programming Statements 213

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

Saved successfully!

Ooh no, something went wrong!