Apex - do while循环
2019-10-26 16:26 更新
Do While循环
与for和while循环测试循环顶部的循环条件不同,do ... while循环在循环底部检查其条件。
一个do ... while循环类似于一个while循环,除了一个do ... while循环被保证至少执行一次。
一个do ... while循环类似于一个while循环,除了一个do ... while循环被保证至少执行一次。
语法:
do { code_to_execute } while (Boolean_condition);流程图:

例如:
对于我们的化学公司,我们将更新列表中唯一的第一个记录,不超过。
//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以上内容是否对您有帮助:

免费 AI IDE


更多建议: