Rexx - if else 語句



下一個決策語句是 if-else 語句。一個if語句可以後跟一個可選的else語句,當布林表示式為假時執行。

語法

Rexx 中此語句的一般形式如下所示:−

if (condition) then 
   do 
      #statement1 
      #statement2 
   end 
else 
   do 
      #statement3 
      #statement4 
   end 

在 Rexx 中,條件是一個表示式,它計算結果為真或假。如果條件為真,則執行後續語句。否則,如果條件計算結果為假,則計算 else 條件中的語句。

流程圖

if-else 語句的流程圖如下所示:−

If Else

從上圖可以看出,我們有兩個程式碼塊。如果條件計算結果為真,則執行一個程式碼塊;如果程式碼計算結果為假,則執行另一個程式碼塊。

以下程式是 Rexx 中簡單 if-else 表示式的示例。

示例

/* Main program */ 
i = 50 
if (i < 10) then 
   do 
      say "i is less than 10" 
   end  
else 
   do 
      say "i is greater than 10" 
   end 

以上程式碼的輸出將是:−

i is greater than 10 
rexx_decision_making.htm
廣告
© . All rights reserved.