Welcome to AE Resources
Converted document Converted document

FORTRAN 90+: SELECT CASE EXAMPLES

PROGRAM example
          IMPLICIT NONE
          INTEGER ::years_in_college
          WRITE(*,*) ‘‘How many years did you spend in’’ &
                     ‘‘college earning degrees?’’
          READ(*,*) years_in_college
          SELECT CASE (years_in_college)
               CASE (:1)
                    WRITE(*,*) ‘‘NO DEGREE’’
               CASE (2)
                    WRITE(*,*) ‘‘ASSOCIATE’’
               CASE (3:5)
                    WRITE(*,*) ‘‘BACHELOR OF SCIENCE’’
               CASE (6:7)
                    WRITE(*,*) ‘‘MASTER OF SCIENCE’’
               CASE (8: )
                    WRITE(*,*) ‘‘YOU’RE A MAD SCIENTIST’’
          END SELECT
     END PROGRAM
PROGRAM example2
          IMPLICIT NONE
          CHARACTER(LEN=20) :: interest
          WRITE(*,*) ‘‘Is your interest in Jets,’’ &
                     ‘‘Rotorcraft, or Spacecraft?’’
          READ(*,*) interest
          SELECT CASE (interest)
               CASE (‘‘Jets’’)
                    WRITE(*,*) ‘‘Work for Boeing’’
               CASE (‘‘Rotorcraft’’)
                    WRITE(*,*) ‘‘Work for Bell’’
               CASE (‘‘Spacecraft’’)
                    WRITE(*,*) ‘‘Work for SpaceX’’
          END SELECT
     END PROGRAM