Java Standard For Loops
The standard `for` loop packages counter initialization, loop condition, and step update all into a single, elegant header. It is the gold standard when you know exactly how many times you need to repeat an action.
"A for loop is like a lap counter on a running track with a set goal: "Start at lap 1, run until lap 5, adding 1 lap each time around.""
Deep Dive: How It Works
Structure: `for (initialization; condition; update) { ... }`
Step 1: Initialization runs once at the beginning (`int i = 0`).
Step 2: Condition is evaluated before each iteration (`i < 5`).
Step 3: Body statements execute.
Step 4: Update runs after each iteration (`i++`), then returns to Step 2.
Syntax Blueprint
for (int i = 0; i < 5; i++) {
System.out.println("Index: " + i);
}The loop variable i only exists inside the for loop scope.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Using commas instead of semicolons in loop header: for (int i = 0, i < 5, i++)Why it happens: Clauses in a for header must be separated by semicolons.
How to fix: Use semicolons: for (int i = 0; i < 5; i++).
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Print even numbers up to 6
Write a for loop that prints even numbers: 2, 4, 6.
Start at int i = 2; continue while i <= 6; increment by i += 2.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.