For Loops
Apex supports three variations of the for loop:
-
The traditional
forloop, where init_stmt, exit_condition, increment_stmt, and code_block are placeholder values: -
The list or set iteration
forloop, where variable must be of the same primitive or sObject type as list_or_set. -
The SOQL
forloop:or
Both variable and variable_list must be of the same sObject type as is returned by the soql_query.
Curly braces ({}) are required around a code_block only if the block contains more than one statement.
Each is discussed further in the sections that follow.