Fortran教學
Fortran語言環境設置
Fortran基本語法
Fortran數據類型
Fortran變量
Fortran常量
Fortran運算符
Fortran算術運算符
Fortran關係運算符
Fortran邏輯運算符
Fortran運算符優先級
Fortran選擇決策
Fortran if...then語句結構
Fortran if...then...else 結構
Fortran if...else if...else 語句
Fortran嵌套if結構
Fortran select case結構
Fortran嵌套select case結構
Fortran循環
Fortran do循環結構
Fortran do...while循環結構
Fortran嵌套循環
Fortran exit語句
Fortran Cycle語句
Fortran Stop語句
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