O'Reilly logo

The Developer’s Guide to the Force.com Platform by Phil Choi, Andrew Fawcett, Glen Martin, Rick Greenwald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Apex Loops

Apex supports the three standard types of loops for implementing repeated actions: Do-while, While, and For loops.

Do-while Loops

A Do-while loop repeatedly executes a set of code statements. The syntax for the loop is as follows:

do {
 code_block;
       }
       while (Boolean_condition);

The code within the curly braces executes and then the condition is evaluated. A Do-while loop always executes at least once.

While Loops

A While loop is like a do-while loop, except that the while condition is evaluated before any of the statements in the code are executed. Because of this, the code in a While loop might not be executed at all. The syntax for the While loop is as follows:

while (Boolean_condition) {
 code_block;
       };

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required