Apex - 嵌套if语句
2019-10-26 16:26 更新
嵌套if-else
我们也可以有复杂条件的嵌套if-else语句,如下所示:
语法:
if boolean_expression_1 { / Executes when the boolean expression 1 is true / if boolean_expression_2 { / Executes when the boolean expression 2 is true / } }
示例:
String pinCode = '12345'; String customerType = '12345'; if (pinCode == '12345') { System.debug('Condition met and Pin Code is'+pinCode);
</span><span>if</span><span>(</span><span>customerType </span><span>==</span><span> </span><span>'Premium'</span><span>)</span><span> </span><span>{</span><span>
</span><span>System</span><span>.</span><span>debug</span><span>(</span><span>'This is a Premium customer living in pinCode 12345');
}
else if(customerType == '</span><span>Normal</span><span>') {
System.debug('</span><span>This</span><span> </span><span>is</span><span> a </span><span>Normal</span><span> customer living </span><span>in</span><span> pinCode </span><span>12345</span><span>');</span><span>
</span><span>}</span><span>
}else { //this can go on as per the requirement System.debug('Pincode not found');}
以上内容是否对您有帮助:
更多建议: