Loop boundary explorer
Change a JavaScript loop’s start, boundary and step. See the values it visits, the first failed condition and loops that never finish.
Free to use · No sign-up · Inputs stay in your browser
Change one thing. Follow the loop.
Try changing < to <= first. Predict the extra value before looking at the trace.
The loop you are exploring
for (let i = 0; i < 5; i += 1) {
console.log(i);
}Trace the boundary
5 iterations.
| Visit | Condition before the body |
|---|---|
| 1 | 0 < 5 → true |
| 2 | 1 < 5 → true |
| 3 | 2 < 5 → true |
| 4 | 3 < 5 → true |
| 5 | 4 < 5 → true |
First failed check
5 < 5 → false
The body does not run for this value. The loop is finished.
Practice predicting a boundary
With i starting at 1, i < 4 and a step of 1, which values reach the body and which check stops the loop?
Check the reasoning
The body sees 1, 2 and 3. After the third increment, 4 < 4 is false. State the final failed check as well as the visited values; it exposes the boundary assumption.
This is an original open example, not a scored drill. Close the tool before taking a diagnostic or an unassisted practice session.
About 14 minutes, no account needed. A free account adds a daily practice queue; paid plans add more practice and the full library.
How to use the result
Choose whole numbers and a comparison. The preview shows at most the first twelve visited values and the final failed check. The loop body only logs i; it does not change i, the boundary or the step.
With start 0, boundary 5, comparison < and step 1, the body runs five times: 0, 1, 2, 3, 4. The first failed check is 5 < 5.
These utilities and open examples do not contribute to your diagnostic score or practice history.
MDN: loops and iteration