Control Flow Statements

Apex provides if-else statements, switch statements, and loops to control the flow of code execution. Statements are generally executed line by line, in the order they appear. With control flow statements, you can make Apex code execute based on a certain condition, or have a block of code execute repeatedly.

  • Conditional (If-Else) Statements

    The conditional statement in Apex works similarly to Java.

  • Switch Statements

    Apex provides a switch statement that tests whether an expression matches one of several values and branches accordingly.

  • Loops

    Apex supports five types of procedural loops.