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.

9 Program Structure Control Statements<br />

9.1 Introduction<br />

The use of structured programming statements has been found to encourage better programming and design<br />

practices among beginners, and aids the more experienced programmer in writing error-free programs.<br />

The format of these statements and their blocks is illustrated below. Following this, the use and meaning of<br />

each statement is described and illustrated with examples. In each of these illustrations, the blocks are<br />

denoted by statement(s) and are delimited by control statements.<br />

In the descriptions, logical-expression can also be an integer expression, in which case the result<br />

of the integer expression is compared for inequality to the integer value 0.<br />

Example:<br />

IF( LEN - 1 )THEN<br />

In the preceding example, the expression LEN - 1 is interpreted as LEN - 1 .NE. 0.<br />

9.2 IF - ELSE - END IF<br />

The ELSE portion of this construct is optional, thus there are two possible formats.<br />

(a) IF( logical-expression )THEN<br />

statement(s)<br />

END IF<br />

(b) IF( logical-expression )THEN<br />

statement(s)<br />

ELSE<br />

statement(s)<br />

END IF<br />

[: block-label]<br />

[: block-label]<br />

This construct is an enhancement of the <strong>FORTRAN</strong> logical IF statement. If the value of the parenthesized<br />

logical expression is true in (a), the block of statements following the IF statement is executed, after which<br />

control passes to the statement following the END IF statement; otherwise, control will pass directly to the<br />

statement following the END IF statement. When the ELSE statement is used and the logical expression<br />

is true, the block of statements between the IF and the ELSE statements is executed and then control<br />

passes to the statement following the END IF statement; otherwise the block of statements following<br />

ELSE statement is executed and then control passes to the statement following the END IF statement.<br />

An optional block label may be specified with the IF statement (see the CYCLE, EXIT or QUIT<br />

statement for more information).<br />

IF - ELSE - END IF 193

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

Saved successfully!

Ooh no, something went wrong!