W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎勵
if語句后面可以跟一個(gè)可選的else if ... else語句,這對于使用single if ... else if語句測試各種條件非常有用。
語法:
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 */ }
例如:
假設(shè),我們的化工公司有兩類客戶:高級和正常。 根據(jù)客戶類型,我們應(yīng)該提供折扣和其他好處,如售后服務(wù)和支持。 下面是這個(gè)的實(shí)現(xiàn)。
//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'); }
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: