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.

Program Structure Control Statements<br />

Example:<br />

LOOP<br />

READ *, X<br />

IF( X .EQ. 99.0 )EXIT<br />

PRINT *, X<br />

END LOOP<br />

The above statements cause values to be read and printed, one to a line, until the value 99.0 is read. When<br />

variable X has this value, the logical expression in the IF statement evaluates as true and the EXIT<br />

statement causes a transfer of control to the statement following the END LOOP statement. The EXIT<br />

statement is discussed in more detail in a later section.<br />

9.7 WHILE - END WHILE<br />

WHILE( logical-expression )DO<br />

statement(s)<br />

END WHILE<br />

[: block-label]<br />

This extension to <strong>FORTRAN</strong> <strong>77</strong> causes its block of code to be executed repeatedly while the parenthesized<br />

logical expression is true. The logical expression is evaluated before entry to the block. If the value is<br />

false, control passes to the statement following the END WHILE statement. If the logical expression is<br />

true, the statements of the block are executed. When the END WHILE statement is reached, the WHILE<br />

logical expression is re-evaluated and the above program control decisions are repeated. An optional block<br />

label may be specified (see the CYCLE, EXIT or QUIT statement for more information). An example<br />

follows:<br />

Example:<br />

WHILE( J .GT. 0 )DO<br />

A(J) = B(I + J)<br />

J = J - 1<br />

END WHILE<br />

If variable J is zero or negative when the WHILE statement is executed, the WHILE block of code will be<br />

by-passed and the statement following the END WHILE statement will be executed.<br />

If variable J is greater than zero when the WHILE statement is executed, the WHILE block will be executed<br />

repeatedly until J becomes equal to zero. The effect of this loop will be to assign values to elements of<br />

array A from array B, starting with the element of A corresponding to the initial value of variable J and<br />

working backwards down the array to element 1.<br />

9.8 WHILE - Executable-statement<br />

WHILE( logical-expression )stmt<br />

WHILE - Executable-statement 199

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

Saved successfully!

Ooh no, something went wrong!