W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
if語句后面可以有一個(gè)可選的else語句,當(dāng)布爾表達(dá)式為false時(shí)執(zhí)行。
語法:
if boolean_expression { /* statement(s) will execute if the boolean expression is true */ } else { /* statement(s) will execute if the boolean expression is false */ }如果布爾表達(dá)式的計(jì)算結(jié)果為true,則將執(zhí)行if代碼塊,否則將執(zhí)行代碼塊。
流程圖:
//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 { 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'); }由于“Glenmarkone”是一個(gè)高級(jí)客戶,所以if塊將基于條件執(zhí)行,在其余情況下,else條件將被觸發(fā)。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: