Apex - 嵌套if語句

2019-10-26 16:26 更新

嵌套if-else

我們也可以有復(fù)雜條件的嵌套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');}

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號