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.51 Logical IF Statement<br />

<br />

IF (e) st<br />

where:<br />

e<br />

st<br />

is a logical expression or integer arithmetic expression, in which case the result of the integer<br />

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

is an executable statement. Only certain executable statements are allowed. See the section entitled<br />

"Classifying Statements" on page 9 at the beginning of this chapter for a list of allowable statements.<br />

The expression e is evaluated and must result in a true or a false value. If the result is true then the<br />

statement st is executed, otherwise it is not executed.<br />

Example:<br />

IF( A .LT. B )PRINT *, ’A < B’<br />

In the above example, the logical expression A .LT. B is evaluated and, if it is true, the message A <<br />

B is printed. A logical expression is one in which the result is either true or false. An expression such as 1<br />

+ 2 is clearly not an example of a logical expression.<br />

Logical variables have logical values of true or false and may also be used in the logical expression.<br />

Consider the following two examples.<br />

Example:<br />

LOGICAL RESULT<br />

RESULT = A .LT. B<br />

IF( RESULT )PRINT *, ’A < B’<br />

The above example is equivalent to the preceding one but introduces the use of a logical variable.<br />

Example:<br />

LOGICAL RESULT<br />

RESULT = A .LT. B<br />

IF( .NOT. RESULT )PRINT *, ’A >= B’<br />

In the above example, the logical expression is negated through the use of the .NOT. operator in order to<br />

test for the inverse condition, namely .GE..<br />

Much more complex logical expressions can be constructed and then tested for their truth value.<br />

Example:<br />

IF( A.LT.B .OR. C.GE.D )PRINT *, ’A=D’<br />

Logical IF Statement 85

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

Saved successfully!

Ooh no, something went wrong!