What will the following code output?
a = 10
while a > 0:
x = a + 1
print(x)11 11 11 ...
The while loop checks if a is greater than 0. That's always true since a is 10. Then the loops performs x = 10 + 1 and then prints x which happens to be 11, always.
What does the following code output?
a = 0
while a < 5:
a = a + 1
print(a)1 2 3 4 5
At first a is 0. The loop checks if a is less than 5, which is true in the first iteration. Then, a = a + 1 adds 1 to a, so now a is 1 and 1 is printed out. The next loop does a = 1 + 1 so a becomes 2. The third loop does a = 2 + 1, so a becomes 3 and so the loop continues until a is not less than 5 anymore.