Do While循環(huán)
與for和while循環(huán)測(cè)試循環(huán)頂部的循環(huán)條件不同,do ... while循環(huán)在循環(huán)底部檢查其條件。
一個(gè)do ... while循環(huán)類似于一個(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
更多建議: