Python Standard For Loops & Iteration
The classic for loop consists of three expressions: initialization, condition test, and increment/step update. It provides precise, index-based iteration over numbers and collections.
"A for loop is like a lap counter on a racetrack: you start at lap 1, check if you have completed 10 laps, and increment the counter at the finish line of every lap."
Deep Dive: How It Works
3-Part Header: for (let i = 0; i < limit; i++) { ... }
Scoped Index Variable: Using let i scopes the variable strictly to the loop body.
Step Control: You can increment by any step (e.g., i += 2) or decrement (i--).
Syntax Blueprint
for (initialization; condition; update) { // body }Initialization runs once, condition is checked before each turn, and update runs after each turn.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Off-by-one errors with <= vs <.Why it happens: For a 5-item list, looping with i <= 5 attempts to read index 5, which is out of bounds.
How to fix: Use i < array.length for zero-indexed array boundaries.
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.
Calculate product with a for loop
Calculate factorial of 4 (1 * 2 * 3 * 4 = 24).
Initialize let product = 1;
Use a for loop from i = 1 to i <= 4, multiplying product *= i.
Print "Product: 24".
Finished reading and practicing?
Mark this lesson as completed to update your course progress.