- Apex 编程教程
- Apex - 主页
- Apex - 概述
- Apex - 环境
- Apex - 示例
- Apex - 数据类型
- Apex - 变量
- Apex - 字符串
- Apex - 数组
- Apex - 常量
- Apex - 决策制定
- Apex - 循环
- Apex - 集合
- Apex - 类
- Apex - 方法
- Apex - 对象
- Apex - 接口
- Apex - DML
- Apex - 数据库方法
- Apex - SOSL
- Apex - SOQL
- Apex - 安全性
- Apex - 调用
- Apex - 触发器
- Apex - 触发器设计模式
- Apex - 管理限制
- Apex - 批量处理
- Apex - 调试
- Apex - 测试
- Apex - 部署
- Apex 有用资源
- Apex - 快速指南
- Apex - 资源
- Apex - 讨论
Apex - if elseif else 语句
if 语句后面可接一个可选的 else if...else 语句,这对于使用单个 if...else if 语句来测试各种条件很有用。
语法
if...else if...else 语句的语法如下:
if boolean_expression_1 { /* Executes when the boolean expression 1 is true */ } else if boolean_expression_2 { /* Executes when the boolean expression 2 is true */ } else if boolean_expression_3 { /* Executes when the boolean expression 3 is true */ } else { /* Executes when the none of the above condition is true */ }
示例
假设我们的化学公司有两个类别的客户 - 高级和普通。根据客户类型,我们应该为他们提供诸如售后服务和支持之类的折扣和其他优惠。以下程序显示了相同的实现。
//Execute this code in Developer Console and see the Output String customerName = 'Glenmarkone'; //premium customer Decimal discountRate = 0; Boolean premiumSupport = false; if (customerName == 'Glenmarkone') { discountRate = 0.1; //when condition is met this block will be executed premiumSupport = true; System.debug('Special Discount given as Customer is Premium'); }else if (customerName == 'Joe') { discountRate = 0.5; //when condition is met this block will be executed premiumSupport = false; System.debug('Special Discount not given as Customer is not Premium'); }else { discountRate = 0.05; //when condition is not met and customer is normal premiumSupport = false; System.debug('Special Discount not given as Customer is not Premium'); }
apex_decision_making.htm
广告