Lahey/Fujitsu Fortran



The SELECT CASE statement signals the beginning of a CASE construct. It contains an expression that, when evaluated, produces a case index. The case index in the SELECT CASE Statement determines which block in a SELECT CASE Statement, if any, is executed.

The END SELECT statement signals the end of the innermost nested SELECT CASE Statement.



[construct-name :] SELECT CASE (case-expr) ... END SELECT [construct-name]

construct-name is an optional name for the SELECT CASE Statement

case-expr is a scalar expression of type INTEGER, LOGICAL, CHARACTER or case-value : case-value


Execution of a SELECT CASE statement causes the case expression to be evaluated. The resulting value is called the case index.

Execution of a CASE code block occurs if the case index derived from the SELECT CASE statement is in the range specified by the CASE statement's case-selector. Execution of the code block ends when any subsequent CASE or END CASE statement is encountered, and the innermost SELECT CASE Statement is exited.

If the SELECT CASE statement is identified by a construct-name, the corresponding END SELECT statement must be identified by the same construct name. If the SELECT CASE statement is not identified by a construct-name, the corresponding END SELECT statement must not have a construct-name.

Example 1

integer :: i=3 select case (i) case (:-2) write(*,*) "i is less than or equal to -2" case (0) write(*,*) "i is equal to 0" case (1:97) write(*,*) "i is in the range 1 to 97, inclusive" case default write(*,*) "i is either -1 or greater than 97" end select

Example 2

character(len=5) :: c="Howdy" select case (c) case ("Hi","Hello","Howdy") write(*,*) "Hello, how are you?" case ("Good Morning") write(*,*) "Nice morning, isn't it?" case ("Good Night") write(*,*) "Goodbye." case default write(*,*) "What time is it?" end select

See Also

CASE Construct