鍍金池/ 教程/ Java/ Fortran嵌套if結(jié)構(gòu)
Fortran還原功能
Fortran關(guān)系運(yùn)算符
Fortran運(yùn)算符優(yōu)先級(jí)
Fortran基本語法
Fortran文件輸入輸出
Fortran嵌套select case結(jié)構(gòu)
Fortran變量
Fortran Cycle語句
Fortran語言環(huán)境設(shè)置
Fortran數(shù)據(jù)類型
Fortran數(shù)組
Fortran字符
Fortran if...else if...else 語句
Fortran調(diào)試程序
Fortran編程風(fēng)格
Fortran if...then語句結(jié)構(gòu)
Fortran嵌套循環(huán)
Fortran常量
Fortran循環(huán)
Fortran導(dǎo)出數(shù)據(jù)類型
Fortran字符串
Fortran操作函數(shù)
Fortran do...while循環(huán)結(jié)構(gòu)
Fortran內(nèi)部函數(shù)
Fortran數(shù)字精度
Fortran選擇決策
Fortran重塑函數(shù)
Fortran運(yùn)算符
Fortran構(gòu)造函數(shù)
Fortran模塊
Fortran位置函數(shù)
Fortran數(shù)字
Fortran指針
Fortran算術(shù)運(yùn)算符
Fortran exit語句
Fortran動(dòng)態(tài)數(shù)組
Fortran嵌套if結(jié)構(gòu)
Fortran select case結(jié)構(gòu)
Fortran向量和矩陣乘法函數(shù)
Fortran邏輯運(yùn)算符
Fortran if...then...else 結(jié)構(gòu)
Fortran教程
Fortran過程
Fortran Stop語句
Fortran基本輸入輸出
Fortran do循環(huán)結(jié)構(gòu)
Fortran查詢函數(shù)

Fortran嵌套if結(jié)構(gòu)

可以使用一個(gè) if 或else if 在另一個(gè)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

當(dāng)上述代碼被編譯和執(zhí)行時(shí),它產(chǎn)生了以下結(jié)果:

Value of a is 100 and b is 200
exact value of a is 100
exact value of b is 200