- Fortran 教程
- Fortran - 主页
- Fortran - 概述
- Fortran - 环境设置
- Fortran - 基本语法
- Fortran - 数据类型
- Fortran - 变量
- Fortran - 常量
- Fortran - 运算符
- Fortran - 决策
- Fortran - 循环
- Fortran - 数字
- Fortran - 字符
- Fortran - 字符串
- Fortran - 数组
- Fortran - 动态数组
- Fortran - 派生数据类型
- Fortran - 指针
- Fortran - 基本输入输出
- Fortran - 文件输入输出
- Fortran - 过程
- Fortran - 模块
- Fortran - 内在函数
- Fortran - 数值精度
- Fortran - 程序库
- Fortran - 编程风格
- Fortran - 调试程序
- Fortran 资源
- Fortran - 快速指南
- Fortran - 有用的资源
- Fortran - 讨论
Fortran - 嵌套 If 构造
您可以在另一个 if 或 else if语句中使用一个 if 或 else if 语句。
句法
嵌套if语句的语法如下 -
if ( logical_expression 1) then
!Executes when the boolean expression 1 is true
…
if(logical_expression 2)then
! Executes when the boolean expression 2 is true
…
end if
end if
例子
program nestedIfProg
implicit none
! local variable declaration
integer :: a = 100, b= 200
! check the logical condition using if statement
if( a == 100 ) then
! if condition is true then check the following
if( b == 200 ) then
! if inner if condition is true
print*, "Value of a is 100 and b is 200"
end if
end if
print*, "exact value of a is ", a
print*, "exact value of b is ", b
end program nestedIfProg
当上面的代码被编译并执行时,它会产生以下结果 -
Value of a is 100 and b is 200 exact value of a is 100 exact value of b is 200
fortran_decisions.htm