- Rexx 教程
- Rexx - 首页
- Rexx - 概述
- Rexx - 环境
- Rexx - 安装
- Rexx - 插件安装
- Rexx - 基本语法
- Rexx - 数据类型
- Rexx - 变量
- Rexx - 运算符
- Rexx - 数组
- Rexx - 循环
- Rexx - 决策
- Rexx - 数字
- Rexx - 字符串
- Rexx - 函数
- Rexx - 堆栈
- Rexx - 文件 I/O
- Rexx - 文件函数
- Rexx - 子程序
- Rexx - 内置函数
- Rexx - 系统命令
- Rexx - XML
- Rexx - Regina
- Rexx - 解析
- Rexx - 信号
- Rexx - 调试
- Rexx - 错误处理
- Rexx - 面向对象
- Rexx - 可移植性
- Rexx - 扩展函数
- Rexx - 指令
- Rexx - 实现
- Rexx - Netrexx
- Rexx - Brexx
- Rexx - 数据库
- 手持设备与嵌入式系统
- Rexx - 性能
- Rexx - 最佳编程实践
- Rexx - 图形用户界面
- Rexx - Reginald
- Rexx - Web 编程
- Rexx 有用资源
- Rexx - 快速指南
- Rexx - 有用资源
- Rexx - 讨论
Rexx - 决策
决策结构要求程序员指定一个或多个条件,由程序进行评估或测试。
下图显示了大多数编程语言中典型的决策结构的通用形式。
如果条件确定为true,则执行一个或多个语句;或者,如果条件确定为false,则可以选择执行其他语句。
让我们看看 Rexx 中可用的各种决策语句。
| 序号 | 语句及描述 |
|---|---|
| 1 | If 语句
第一个决策语句是if语句。if语句由一个布尔表达式和一个或多个语句组成。 |
| 2 | If-else 语句
下一个决策语句是 if-else 语句。if语句后面可以跟一个可选的 else 语句,当布尔表达式为 false 时执行。 |
嵌套 If 语句
有时需要在彼此内部嵌套多个 if 语句,这在其他编程语言中也是可能的。在 Rexx 中也可以做到这一点。
语法
if (condition1) then
do
#statement1
end
else
if (condition2) then
do
#statement2
end
流程图
嵌套if语句的流程图如下:
让我们来看一个嵌套if语句的例子:
示例
/* Main program */
i = 50
if (i < 10) then
do
say "i is less than 10"
end
else
if (i < 7) then
do
say "i is less than 7"
end
else
do
say "i is greater than 10"
end
上述程序的输出将是:
i is greater than 10
Select 语句
Rexx 提供 select 语句,可用于根据 select 语句的输出执行表达式。
语法
此语句的通用形式为:
select when (condition#1) then statement#1 when (condition#2) then statement#2 otherwise defaultstatement end
此语句的通用工作原理如下:
select 语句有一系列 when 语句来评估不同的条件。
每个when 子句都有一个不同的条件需要评估,然后执行后续语句。
如果之前的 when 条件不评估为 true,则使用 otherwise 语句运行任何默认语句。
流程图
select语句的流程图如下:
以下程序是 Rexx 中 case 语句的示例。
示例
/* Main program */ i = 50 select when(i <= 5) then say "i is less than 5" when(i <= 10) then say "i is less than 10" otherwise say "i is greater than 10" end
上述程序的输出将是:
i is greater than 10
广告