Rexx - If else 语句
下一个决策语句是 if-else 语句。 if 语句后面可以跟一个可选的 else 语句,该语句在布尔表达式为 false 时执行。
语法
Rexx 中该语句的一般形式如下。 −
if (condition) then
do
#statement1
#statement2
end
else
do
#statement3
#statement4
end
在 Rexx 中,条件是一个计算结果为 true 或 false 的表达式。 如果条件为真,则执行后续语句。 else 如果条件评估为 false,则评估 else 条件中的语句。
流程图
if-else语句的流程图如下 −
从上图中可以看出,我们有两个代码块。 如果条件评估为 true,则执行一个,如果代码评估为 false,则执行另一个。
以下程序是 Rexx 中简单 if-else 表达式的示例。
示例
/* 主程序 */
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

