Apex-do-while-loop

提供:Dev Guides
移動先:案内検索

Apex-do-whileループ

ループの上部でループ条件をテストする for および while ループとは異なり、 do …​ while ループはループの下部でその状態をチェックします。

do …​ whileループは、do …​ whileループが少なくとも1回実行されることが保証されていることを除いて、whileループに似ています。

構文

do { code_to_execute } while (Boolean_condition);

流れ図

Apex do-whileループ

化学会社の場合、リストの最初の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