# 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.

- Canonical HTML: [https://unrust.dev/tools/loop-boundary-explorer](https://unrust.dev/tools/loop-boundary-explorer)
- Markdown representation: [https://unrust.dev/tools/loop-boundary-explorer/index.md](https://unrust.dev/tools/loop-boundary-explorer/index.md)

## How to use the tool

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.

## Worked example

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.

```text
for (let i = 0; i < 5; i += 1) {
  console.log(i);
}
```

Inputs stay in your browser. These are open learning examples, not scored diagnostic drills.

[Find an off-by-one error before running the loop](https://unrust.dev/blog/off-by-one-loop-boundaries/index.md)

[MDN: loops and iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration)

## 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?

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.

Original open example, not a scored drill. Close tools before an unassisted session.

[Practice tracing code without running it](https://unrust.dev/guides/code-tracing/index.md)

[Take the free diagnostic](https://unrust.dev/diagnostic/index.md)
