next up previous contents
Next: Visualisation of SELECT CASE Up: Control Constructs Previous: Scope of DO Variables

 

SELECT CASE Construct I

Simple example

    SELECT CASE (i)
      CASE (3,5,7)
        PRINT*,"i is prime"
      CASE (10:)
        PRINT*,"i is > 10"
      CASE DEFAULT
        PRINT*, "i is not prime and is < 10"
    END SELECT

An IF .. ENDIF construct could have been used but a SELECT CASE is neater and more efficient. Another example,

    SELECT CASE (num)
      CASE (6,9,99,66) 
!     IF(num==6.OR. .. .OR.num==66) THEN
        PRINT*, "Woof woof"
      CASE (10:65,67:98)
!     ELSEIF((num >= 10 .AND. num <= 65) .OR. ...
        PRINT*, "Bow wow"
      CASE DEFAULT
!     ELSE
        PRINT*, "Meeeoow"
     END SELECT     
!    ENDIF


next up previous contents
Next: Visualisation of SELECT CASE Up: Control Constructs Previous: Scope of DO Variables

©University of Liverpool, 1997
Wed May 28 23:37:18 BST 1997
Not for commercial use.