I am wondering why this code seems to loop infinitely? The logic, while not False = while True
, and this True is referring to 100 < 0
which is false, hence it should execute the print statement instead, right? Why is it stuck in the loop then..?
num = 100
while not False:if num < 0:break
print('num is: ' + str(num))
a while
statement should be proceeded with a conditional. The conditional True
(or in your cause not False
) always evaluates to True
so the loop never ends.
the if
block is never executed because because num < 0
never evaluates to True
. Did you mean to decrement num by 1 in each iteration of the while
block? If so, add a num = num - 1
within the while
block:
num = 100
while not False:if num < 0:breaknum = num - 1
print('num is: ' + str(num))