SELECT CASE Statement

Fortran has one more selective execution statement, SELECT CASE, and could be very handy if it is used properly. The SELECT CASE statement is also usually referred to as the CASE statement. The following is its syntactic form:

SELECT CASE (selector)
   CASE (label-list-1)
      statements-1
   CASE (label-list-2)
      statements-2
   CASE (label-list-3)
      statements-3
     .............
   CASE (label-list-n)
      statements-n
   CASE DEFAULT
      statements-DEFAULT
END SELECT
where statements-1, statements-2, statements-3, ..., statements-n and statements-DEFAULT are sequences of executable statements, including the SELECT CASE statement itself, and selector is an expression whose result is of type INTEGER, CHARACTER or LOGICAL (i.e., no REAL type can be used for the selector). The label lists label-list-1, label-list-2, label-list-3, ..., and label-list-n are called case labels.

A label-list is a list of labels, separated by commas. Each label must be one of the following forms. In fact, three of these four are identical to an extent specifier for substrings:

value
value-1 : value-2
value-1 :
 : value-2
where value, value-1 and value-2 are constants or alias defined by PARAMETER. The type of these constants must be identical to that of the selector. The rule of executing the SELECT CASE statement goes as follows: There are some notes for writing good Fortran programs:

Examples