目录

nested if statement

对于复杂条件,我们也可以使用嵌套的if-else语句,如下所示 -

语法 (Syntax)

if boolean_expression_1 {
   /* Executes when the boolean expression 1 is true */
   if boolean_expression_2 {
      /* Executes when the boolean expression 2 is true */
   }
}

例子 (Example)

String pinCode = '12345';
String customerType = '12345';
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 {
   //this can go on as per the requirement
   System.debug('Pincode not found');
}
↑回到顶部↑
WIKI教程 @2018