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:
- do {statement} while (Boolean_condition);
- while (Boolean_condition) statement;
- for (initialization; Boolean_exit_condition; increment) statement;
- for (variable : array_or_set) statement;
- 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