Rexx 程式設計/Rexx 指南/if
外觀
if 條件結構允許根據布林表示式的結果有條件地執行 語句 或 程式碼塊。只有當表示式計算結果為真值時,條件中的分支才會執行。if 條件最簡單的形式是
例如
if guess = 6 then say "Wow! That was a lucky guess."
請注意,Rexx 程式語言語法不使用 endif 作為語法組成部分。下面示例中放置在註釋中的 endif 僅用於美觀目的,以幫助縮排。這些註釋會被 Rexx 直譯器忽略。
if guess = 6 then say "Wow! That was a lucky guess." else say "Sorry! That was not the right number." /* endif */
為了有條件地在條件分支內執行多個語句,有必要將這些語句包含在一個 do 和 end 塊中。
if guess = 6 then
do
say "Wow! That was a lucky guess." /* Multiple statements in a do block */
prize = 30000
end
可以建立巢狀的 if 結構。
if age > 79 then
say "Wow! You are so old that you are almost antique!"
else
if age >=65 then
say "You are a pensioner"
else
if age > 21 then
say "You have the key to the door"
else
say "You are just a youngster"
/* endif */
/* endif */
/* endif */