鍍金池/ 教程/ Java/ Fortran關(guān)系運算符
Fortran還原功能
Fortran關(guān)系運算符
Fortran運算符優(yōu)先級
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運算符
Fortran構(gòu)造函數(shù)
Fortran模塊
Fortran位置函數(shù)
Fortran數(shù)字
Fortran指針
Fortran算術(shù)運算符
Fortran exit語句
Fortran動態(tài)數(shù)組
Fortran嵌套if結(jié)構(gòu)
Fortran select case結(jié)構(gòu)
Fortran向量和矩陣乘法函數(shù)
Fortran邏輯運算符
Fortran if...then...else 結(jié)構(gòu)
Fortran教程
Fortran過程
Fortran Stop語句
Fortran基本輸入輸出
Fortran do循環(huán)結(jié)構(gòu)
Fortran查詢函數(shù)

Fortran關(guān)系運算符

下表列出了所有的Fortran支持的關(guān)系運算符。假設(shè)變量A=10和變量B=20,則:

操作符 等同 描述 示例
== .eq. 檢查兩個操作數(shù)的值相等與否,如果是,則條件變?yōu)檎妗?/td> (A == B) i不為 true.
/= .ne. 檢查,兩個操作數(shù)的值相等與否,如果值不相等,則條件變?yōu)檎妗?/td> (A != B) 為 true.
> .gt. 檢查,左操作數(shù)的值大于右操作數(shù)的值,如果是的話那么條件為真。 (A > B)不為true.
< .lt. 檢查,左操作數(shù)的值是否小于右操作數(shù)的值,如果是的話那么條件為真。 (A < B) 是 true.
>= .ge. 檢查,左邊的操作數(shù)的值是否大于或等于右操作數(shù)的值,如果是,則條件變?yōu)檎妗?/td> (A >= B) 不為 true.
<= .le. 檢查,左邊的操作數(shù)的值是否小于或等于右操作數(shù)的值,如果是,則條件變?yōu)檎妗?/td> (A <= B) 為 true.

示例

試試下面的例子就明白所有在Fortran語言可用的邏輯運算符:

program logicalOp

! this program checks logical operators
implicit none  

   ! variable declaration
   logical :: a, b
   
   ! assigning values 
   a = .true.   
   b = .false. 
   
   if (a .and. b) then
      print *, "Line 1 - Condition is true"
   else
      print *, "Line 1 - Condition is false"
   end if
   
   if (a .or. b) then
      print *, "Line 2 - Condition is true"
   else
      print *, "Line 2 - Condition is false"
   end if
          
   ! changing values 
   a = .false.   
   b = .true. 
   
   if (.not.(a .and. b)) then
      print *, "Line 3 - Condition is true"
   else
      print *, "Line 3 - Condition is false"
   end if
   
   if (b .neqv. a) then
      print *, "Line 4 - Condition is true"
   else
      print *, "Line 4 - Condition is false"
   end if
   
   if (b .eqv. a) then
      print *, "Line 5 - Condition is true"
   else
      print *, "Line 5 - Condition is false"
   end if
   
end program logicalOp

當(dāng)編譯并執(zhí)行上述程序,將產(chǎn)生以下結(jié)果:

Line 1 - Condition is false
Line 2 - Condition is true
Line 3 - Condition is true
Line 4 - Condition is true
Line 5 - Condition is false

上一篇:Fortran數(shù)組下一篇:Fortran過程