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

9.10 SELECT - END SELECT<br />

SELECT [CASE] (e) [FROM] [: block-label]<br />

CASE ( case-list )<br />

statement (s)<br />

CASE ( case-list )<br />

statement (s)<br />

.<br />

.<br />

.<br />

CASE DEFAULT<br />

statement(s)<br />

END SELECT<br />

where:<br />

case-list<br />

is a list of one or more cases separated by commas. A case is either<br />

(a)<br />

(b)<br />

a single integer, logical or character constant expression or<br />

an integer, logical or character constant expression followed by a colon<br />

followed by another expression or the same type. This form of a case defines<br />

a range of values consisting of all integers or characters greater than or equal<br />

to the value of the expression preceding the colon and less than or equal to<br />

the value of the expression following the colon.<br />

The SELECT construct, an extension to <strong>FORTRAN</strong> <strong>77</strong>, is similar in concept to the <strong>FORTRAN</strong> computed<br />

GO TO statement. It allows one of a number of blocks of code (case blocks) to be selected for execution by<br />

means of an integer expression in the SELECT statement.<br />

The SELECT statement keywords, CASE and FROM, are optional. The SELECT statement may contain a<br />

block label (see the CYCLE, EXIT or QUIT statements for more information).<br />

Each block must be started with a CASE statement; however, the last block may begin with a CASE<br />

DEFAULT statement. The CASE DEFAULT block is optional. In order to retain compatibility with earlier<br />

versions of WATCOM <strong>FORTRAN</strong> <strong>77</strong> compilers, the OTHERWISE statement may be used in place of the<br />

CASE DEFAULT statement. The last block is ended by the END SELECT statement. The number of case<br />

blocks is optional, from one to many; however, it is recommended that the SELECT construct not be used<br />

for fewer than 3 case blocks. The conditional execution of one or two blocks of code is handled more<br />

efficiently by the IF-THEN-ELSE construct.<br />

A particular case value or range of values must not be contained in more than one CASE-block. For<br />

example, the following is illegal:<br />

SELECT - END SELECT 201

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

Saved successfully!

Ooh no, something went wrong!