Why loop shoukd termiante in #bw6

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

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

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:

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

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

    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!

1 Like