Apex - do while循環(huán)

2019-10-26 16:26 更新

Do While循環(huán)

與for和while循環(huán)測(cè)試循環(huán)頂部的循環(huán)條件不同,do ... while循環(huán)在循環(huán)底部檢查其條件。

一個(gè)do ... while循環(huán)類(lèi)似于一個(gè)while循環(huán),除了一個(gè)do ... while循環(huán)被保證至少執(zhí)行一次。

語(yǔ)法:
do { code_to_execute } while (Boolean_condition);

流程圖:
流程圖


例如:
對(duì)于我們的化學(xué)公司,我們將更新列表中唯一的第一個(gè)記錄,不超過(guò)。
//Code for do while loop
List<apex_invoice__c> InvoiceList = [SELECT Id, APEX_Description__c, APEX_Status__c FROM APEX_Invoice__c LIMIT 20];//it will fetch only 20 records 	
Integer i =0;
do {
	InvoiceList[i].APEX_Description__c = 'This is the '+i+' Invoice';
	System.debug('****Updated Description'+InvoiceList[i].APEX_Description__c);//This will print the updated description in debug log
	i++;//Increment the counter
}while (i< 1); 
//iterate till 1st record only

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

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)