Python The Standard For Loop & Counting
When you know in advance exactly how many times a block should run (e.g. 10 times, or over every element in an array), the for loop bundles initialization, condition, and increment into a single compact header line.
"A for loop is like a digital lap counter at a track meet: (Start at Lap 1; Run until Lap 10; Add 1 lap each time you cross the finish line)."
Deep Dive: How It Works
Header Structure: for (initialization; condition; increment)
1. Initialization: Runs ONCE at the start (e.g. int i = 0;).
2. Condition: Evaluated before each iteration. If true, body runs. If false, loop terminates.
3. Increment: Executes after the body finishes each loop (e.g. i++ or i += 2).
Scoped Variable: The loop index i is local to the for loop and disappears when the loop finishes.
Syntax Blueprint
for (int i = 0; i < 5; i++) {
std::cout << i << " ";
}Initializes i to 0, loops while i < 5, adds 1 after each cycle (prints 0 1 2 3 4).
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Using commas instead of semicolons in the for header: for(int i=0, i<5, i++)Why it happens: Typo confusion.
How to fix: The three clauses in for(...) must be separated by semicolons (;).
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 2 through 8
Write a for loop starting at int i = 2, running while i <= 8, stepping with i += 2.
Print each number followed by a space.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.