while b:
b -= 2
What is the condition in a line written like this? Does it default to while b > 0?
while b:
b -= 2
What is the condition in a line written like this? Does it default to while b > 0?
Your best bet is to try it. Try running:
b=10
while b:
print(b)
b-=2
and see what happens
Yes, it sure does. b > 0
.
b = 10
while b:
print(b)
b -= 1
A simple print()
statement should let you know when the loop terminates.
Furthermore, this does not mean that the loop will not run for negative b < 0
. This means that the loop will terminate then b = 0
.
b = -1
while b:
print(b)
b -= 1
Goes into an infinite loop.