Break - question


#1

https://www.codecademy.com/courses/learn-python/lessons/loops/exercises/break?action=lesson_resume&link_content_target=interstitial_lesson

I don’t undertstand how this is an infinite loop.

If count = 0, then the count is printed and incremented.
But then, count is not 0 anymore, so the while should stop… right?
Why does it continue until infinity, or in this case, the break? Can anyone explain?

image

count = 0

while True:
  print count
  count += 1
  if count >= 10:
    break

#2

it isn’t, the loop ends thanks to break, so its not an infinity loop

no, while is still evaluating to true thanks to True boolean value at the loop condition. Look at the loop condition:

while True

there is no comparison with zero, so why should the loop stop when count is no longer zero?


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.