- 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
廣告