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.

<strong>Language</strong> <strong>Reference</strong><br />

Examples follow which illustrate the use of the two formats.<br />

Example:<br />

IF( I .EQ. 0 )THEN<br />

PRINT *, ’I IS ZERO’<br />

I = 1<br />

END IF<br />

If variable I is zero when the IF statement is executed, the string I IS ZERO will be printed, variable I<br />

will be assigned the value 1, and the statement following the END IF will be executed. If variable I is not<br />

zero when the IF statement is executed, control will pass to the statement following the END IF<br />

statement.<br />

Example:<br />

IF( A .GT. B )THEN<br />

PRINT *, ’A GREATER THAN B’<br />

A = A - B<br />

ELSE<br />

PRINT *, ’A NOT GREATER THAN B’<br />

END IF<br />

If the value of variable A is greater than the value of variable B when this IF statement is executed, the<br />

string A GREATER THAN B will be printed and variable A will be assigned the value of the expression A<br />

- B. Control will then pass to the statement following the END IF statement.<br />

If the value of variable A is not greater than the value of variable B when the IF statement is executed, the<br />

string A NOT GREATER THAN B will be printed and control will pass to the statement following the<br />

END IF statement.<br />

9.3 ELSE IF<br />

A further enhancement of the IF-THEN-ELSE construct is the ELSE IF statement which may be used in<br />

the following two formats:<br />

(a) IF( logical-expression-1 )THEN [: block-label]<br />

statement(s)<br />

ELSE IF( logical-expression-2 )THEN<br />

statement(s)<br />

...<br />

END IF<br />

(b) IF( logical-expression-1 )THEN [: block-label]<br />

statement(s)<br />

ELSE IF( logical-expression-2 )THEN<br />

statement(s)<br />

...<br />

ELSE<br />

statement(s)<br />

END IF<br />

194 ELSE IF

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

Saved successfully!

Ooh no, something went wrong!