---
schema_version: "1"
id: dd47bbc7d617d97d0d061e77630ac6736098b2428bcca5b3de707cf81f8dea52
title: Traditional For Loops
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexcode/langCon_apex_loops_for_traditional.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_loops_for_traditional.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: d401fcc9d57298fb0ad2a922ff4cc4e10c66c31a22806502a175f1a3a2c8c29c
---
# Traditional For Loops

The traditional for loop in Apex corresponds to the traditional syntax used in Java and other languages. In this syntax, init\_stmt, exit\_condition, increment\_stmt, and code\_block are placeholder values. The syntax is:

for (init\_stmt; exit\_condition; increment\_stmt) {
    code\_block
}

When executing this type of for loop, the Apex runtime engine performs the following steps, in order:

1. Execute the init\_stmt component of the loop. Note that multiple variables can be declared and/or initialized in this statement, separated by commas.
2. Perform the exit\_condition check. If true, the loop continues. If false, the loop exits.
3. Execute the code\_block.
4. Execute the increment\_stmt statement.
5. Return to Step 2.

As an example, the following code outputs the numbers 1–10 into the debug log. Note that an additional initialization variable, j, is included to demonstrate the syntax:

for (Integer i = 0, j = 0; i < 10; i++) {
    System.debug(i+1);
}