if語(yǔ)句由布爾表達(dá)式后跟一個(gè)或多個(gè)語(yǔ)句組成。
語(yǔ)法:
if boolean_expression { /* statement(s) will execute if the boolean expression is true */ }如果布爾表達(dá)式的計(jì)算結(jié)果為true,那么if語(yǔ)句中的代碼塊將被執(zhí)行。 如果布爾表達(dá)式的計(jì)算結(jié)果為false,那么第一組代碼在if語(yǔ)句結(jié)束后(在關(guān)閉大括號(hào)之后)將被執(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'); }因?yàn)椤癎lenmarkone”是一個(gè)高級(jí)客戶,所以if塊將根據(jù)條件執(zhí)行。
更多建議: