0
While Loops1 / 4

CRASH COURSE

While Loops

A while loop repeats as long as its condition is true. Use it when you do not know in advance how many repeats are needed.

  • Something inside the loop must move toward ending it, such as increasing a counter. Otherwise the loop never stops.
  • break exits a loop early, and continue skips to the next repeat. Prefer a clear condition over many breaks.
count = 3
while count > 0:
    print(count)
    count -= 1