Fortran 嵌套 select case 语句

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

语法
  1. select case(a)
  2. case (100)
  3. print*, "This is part of outer switch", a
  4. select case(b)
  5. case (200)
  6. print*, "This is part of inner switch", a
  7. end select
  8. end select
实例
  1. program nestedSelectCase
  2. ! local variable definition
  3. integer :: a = 100
  4. integer :: b = 200
  5. select case(a)
  6. case (100)
  7. print*, "This is part of outer switch", a
  8. select case(b)
  9. case (200)
  10. print*, "This is part of inner switch", a
  11. end select
  12. end select
  13. print*, "Exact value of a is : ", a
  14. print*, "Exact value of b is : ", b
  15. end program nestedSelectCase

结果为:

  1. This is part of outer switch 100
  2. This is part of inner switch 100
  3. Exact value of a is : 100
  4. Exact value of b is : 200

分类导航