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 */