Do-While Loops

The Apex do-while loop repeatedly executes a block of code as long as a particular Boolean condition remains true. Its syntax is:
do {
   code_block
} while (condition);

Curly braces ({}) are always required around a code_block.

Note

As in Java, the Apex do-while loop does not check the Boolean condition statement until after the first loop is executed. Consequently, the code block always runs at least once.

As an example, the following code outputs the numbers 1 - 10 into the debug log:
Integer count = 1;

do {
    System.debug(count);
    count++;
} while (count < 11);