Apex - 嵌套 if 语句
我们还可以为复杂条件使用嵌套的 if-else 语句,如下所示 −
语法
if boolean_expression_1 {
/* 当布尔表达式 1 为 true 时执行 */
if boolean_expression_2 {
/* 当布尔表达式 2 为 true 时执行 */
}
}
示例
String pinCode = '12345';
String customerType = 'Premium';
if (pinCode == '12345') {
System.debug('Condition met and Pin Code is'+pinCode);
if(customerType = 'Premium') {
System.debug('This is a Premium customer living in pinCode 12345');
}else if(customerType = 'Normal') {
System.debug('This is a Normal customer living in pinCode 12345');
}
}else {
//这可以按照要求继续
System.debug('Pincode not found');
}

apex_decision_making.html