! Program Example from "Essential Fortran 90 & 95" by Loren P. Meissner
! Copyright 1996. Copying for sale requires permission from the author.
! Otherwise, distribution is permitted if these three lines are included.

! Example 3.21. Nested case constructs.
  program D21
    implicit none
    integer :: First_Int, Second_Int, Num
    real :: A
! start program D21
    read (unit = *, fmt = *) First_Int, Second_Int
    select case (First_Int)  ! select case statement at level 1
      case (: -1)  ! case block at level 1
        Num = -1
        select case (Second_Int)  ! select case statement at level 2
          case (-5)  ! case block at level 2
            A = 1.0
          case default  ! case default block at level 2
            A = 0.0
        end select  ! end select statement at level 2
      case (0)  ! case block at level 1
        Num = 0
        A = -2.0
      case default  ! case block at level 1
        Num = 1
        A = -3.0
    end select  ! end select statement at level 1
    write (unit = *, fmt = *) Num, A
    stop
  end program D21
