# Why loop shoukd termiante in #bw6

**URL:** <https://forum.codecrafters.io/t/why-loop-shoukd-termiante-in-bw6/9486>\
**Category:** Challenges\
**Tags:** challenge:interpreter\
**Created:** [April 27, 2025, 12:58pm UTC](https://forum.codecrafters.io/t/why-loop-shoukd-termiante-in-bw6/9486 "2025-04-27T12:58:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![m0lt0bene](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/m0lt0bene/32/8833_2.png) [@m0lt0bene](https://forum.codecrafters.io/u/m0lt0bene)\
**Post date:** [April 27, 2025, 12:58pm UTC](https://forum.codecrafters.io/t/why-loop-shoukd-termiante-in-bw6/9486/1 "2025-04-27T12:58:31Z")

</div>

I’m stuck on Stage #bw6  
i dont get why this loop should terminate

```auto
  for (var quz = 0; quz < 1; quz = quz + 1) {
    print quz;
    var quz = -1;
    print quz;
  }
```

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [April 27, 2025, 1:40pm UTC](https://forum.codecrafters.io/t/why-loop-shoukd-termiante-in-bw6/9486/3 "2025-04-27T13:40:09Z")

</div>

Hey @m0lt0bene, there are actually two different variables named `quz`.

The first one is declared in the loop header and is printed the first time:

```auto
  for (var quz = 0; ...) {
    print quz; // 0

```

The second one is declared inside the loop body and is printed the second time:

```auto
    var quz = -1;
    print quz; // -1
  }

```

After the first iteration, the second `quz` (the one inside the loop body) goes out of scope.

Then, `quz = quz + 1` updates the original `quz` from the loop header to 1. Since 1 \< 1 is false, the loop ends.

Let me know if you’d like further clarification!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [May 4, 2025, 7:36pm UTC](https://forum.codecrafters.io/t/why-loop-shoukd-termiante-in-bw6/9486/4 "2025-05-04T19:36:18Z")

</div>

Closed on May 4, 2025, 7:36pm UTC

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
