Ask your own question, for FREE!
Computer Science 24 Online
OpenStudy (osanseviero):

Why is this an infinite loop? (python) num = 100 while not False: if num < 0: break print('num is: ' + str(num))

OpenStudy (anonymous):

Its because you're never decrementing num so num is ALWAYS less than zero and it runs the loop forever.

OpenStudy (osanseviero):

but it says num= 100, so 100 is always higher than 0

OpenStudy (anonymous):

because of exactly that. while not False is actually while True so it will never be lower then 0 (actually in your code it only is 100) so it will never get out of loop.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!