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>Language</strong> <strong>Reference</strong><br />

Example:<br />

* Illegal SELECT block - case value in more<br />

* than one CASE block.<br />

SELECT CASE ( I - 3 )<br />

CASE (1,3,7:10)<br />

statement(s)<br />

CASE (5,6,8)<br />

statement(s)<br />

CASE (-3:-2+4)<br />

statement(s)<br />

END SELECT<br />

The second CASE-block includes 8 which is already handled by the first CASE-block. As well, the third<br />

CASE-block handles cases −3, −2, −1, 0, 1, 2 but the first CASE-block also handles case 1. Thus the<br />

second and third CASE-ranges are in error.<br />

When the SELECT statement case expression is evaluated as i, the case block whose range contains i is<br />

executed and control passes to the statement following the END SELECT statement. If no range contains i,<br />

control is transferred to the statement following the CASE DEFAULT statement, if one is specified. If the<br />

CASE DEFAULT block is omitted and the case expression is out of range when the SELECT statement is<br />

executed (that is, none of the CASE-blocks handles the particular expression value), control is passed to the<br />

statement following the END SELECT statement and none of the CASE-blocks is executed.<br />

Example:<br />

SELECT CASE ( I )<br />

CASE (1)<br />

Y = Y + X<br />

X = X * 3.2<br />

CASE (2)<br />

Z = Y**2 + X<br />

PRINT *, X, Y, Z<br />

CASE (3)<br />

Y = Y * 13. + X<br />

X = X - 0.213<br />

CASE (4)<br />

Z = X**2 + Y**2 - 3.0<br />

Y = Y + 1.5<br />

X = X * 32.0<br />

PRINT *, ’CASE 4’, X, Y, Z<br />

END SELECT<br />

This example will execute in the manner described below for each of the possible values of variable I.<br />

(i)<br />

I is zero or negative:<br />

- control will pass to the statement after the END SELECT statement<br />

(ii) I = 1:<br />

- the value of X will be added to Y<br />

- X will be multiplied by 3.2<br />

- control will pass to the statement after the END SELECT statement<br />

(iii) I = 2:<br />

- Z will be assigned the value of the expression Y**2 + X<br />

- the values of X, Y and Z will be printed<br />

- control will pass to the statement after the END SELECT statement<br />

202 SELECT - END SELECT

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

Saved successfully!

Ooh no, something went wrong!