We’re rewarding the question askers & reputations are being recalculated! Read more.

A loop is a sequence of instructions that is continually repeated until a certain condition is reached.

Apex supports the following five types of procedural loops:

  1. do {statement} while (Boolean_condition);
  2. while (Boolean_condition) statement;
  3. for (initialization; Boolean_exit_condition; increment) statement;
  4. for (variable : array_or_set) statement;
  5. for (variable : [inline_soql_query]) statement;

All loops allow for loop control structures:

  • break; exits the entire loop
  • continue; skips to the next iteration of the loop

Developer Documenation

history | excerpt history