当前位置: 首页 > 文档资料 > Fortran 中文教程 >

嵌套的选择案例构造(nested select case construct)

优质
小牛编辑
135浏览
2023-12-01

您可以在另一个select case语句中使用一个select case语句。

语法 (Syntax)

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

例子 (Example)

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