Fundamentals / Loops
Loops
for, while, and for...of — repetition with a clear exit condition.
A `for` loop packages initialization, a condition, and an update into one line: `for (let i = 0; i < 3; i++)`. On every pass, JavaScript checks the condition first — if it's false, the loop body never runs again. `for...of` iterates values directly (arrays, strings), while `for...in` iterates keys.
`break` exits the loop entirely; `continue` skips straight to the next iteration.
Codeeditable — Run executes your edits
Loading...
Console
Output will appear here
Visualization
Loop Execution
Run the loop to see it iterate
Why?
The condition is checked before every iteration, including the first. The moment i < 3 is false, the loop body is skipped and execution moves to the line after the loop.