目录

do...while循环

while循环顶部测试循环条件的forwhile循环不同, do...while循环do...while循环的底部检查其条件。

do ... while循环类似于while循环,除了do ... while循环保证至少执行一次。

语法 (Syntax)

do { code_to_execute } while (Boolean_condition);

流程图 (Flow Diagram)

Apex do-while Loop

例子 (Example)

对于我们的化学公司,我们将更新列表中唯一的前1个记录,而不是更多。

// 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';
   // This will print the updated description in debug log
   System.debug('****Updated Description'+InvoiceList[i].APEX_Description__c);
   i++; // Increment the counter
} while (i< 1);   // iterate till 1st record only
↑回到顶部↑
WIKI教程 @2018