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 />

SELECT CASE ( CH )<br />

CASE ( ’a’ : ’z’ )<br />

PRINT *, ’Lower case letter’<br />

CASE ( ’A’ : ’Z’ )<br />

PRINT *, ’Upper case letter’<br />

CASE ( ’0’ : ’9’ )<br />

PRINT *, ’Digit’<br />

CASE DEFAULT<br />

PRINT *, ’Special character’<br />

END SELECT<br />

In the above example, if the character CH is not a letter or digit then the CASE DEFAULT block is<br />

executed.<br />

The CASE DEFAULT statement is optional. If it is present and the case expression is out of range (i.e., no<br />

CASE blocks are executed) then the CASE DEFAULT block is executed. If it is not present and the case<br />

expression is out of range then execution continues with the first executable statement following the END<br />

SELECT statement. The CASE DEFAULT block must follow all other CASE blocks.<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 />

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 />

CASE DEFAULT<br />

PRINT *, ’CASE is not in range’<br />

END SELECT<br />

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

In order to retain compatibility with earlier versions of WATCOM <strong>FORTRAN</strong> <strong>77</strong> compilers, the<br />

OTHERWISE statement may be used in place of the CASE DEFAULT statement.<br />

For more information, see the chapter entitled "Program Structure Control Statements" on page 193.<br />

138 SELECT Statement

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

Saved successfully!

Ooh no, something went wrong!