I have the following simple code:
i = 1
j = 6
test = 99
def main():
### i = 1 ### uncommenting this solves the problem with i
while i <= j:
print("i: ", i, "test: ", test)
i += 2
main()
Error:
while i <= j : UnboundLocalError: local variable 'i' referenced before assignment
OK, so inserting the line defining i
inside the function would solve this.
But WHY are the variables j
and test
not affected by this behaviour?
It seems to be special to the first variable of the while loop.