Fortran - 嵌套 select case 结构

您可以在另一个 select case 语句中使用一个 select 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

❮ fortran_decisions.htm