Fortran巢狀select case結構


可以在一個select case語句內嵌另一個選擇case語句。

語法

select case(a) 

   case (100) 
      print*, "This is part of outer switch", a 
      
   select case(b) 
      case (200)
         print*, "This is part of inner switch", a 
         
   end select
      
end select

例子

program nestedSelectCase
   ! local variable definition 
   integer :: a = 100
   integer :: b = 200
 
   select case(a) 
      case (100) 
         print*, "This is part of outer switch", a 
         
      select case(b) 
         case (200)
            print*, "This is part of inner switch", a 
      end select
      
   end select
   
   print*, "Exact value of a is : ", a 
   print*, "Exact value of b is : ", b 
 
end program nestedSelectCase

當上述程式碼被編譯和執行時,它產生了以下結果:

This is part of outer switch 100
This is part of inner switch 100
Exact value of a is : 100
Exact value of b is : 200