for loops in Python are a bit weird

Posted on Sun 11 February 2024 in Python

A quiz:

What does the following JavaScript code print and why?

for (let i = 0; i < 3; i++) {
  console.log(i);
  i -= 3
}

What does the following Python code print and why?

for i in range(3):
    print(i)
    i -= 3