Episode 10 of 29
While Loops
Learn how to repeat code blocks using while loops and when to use them.
While loops repeat code as long as a condition is True.
Basic While Loop
count = 0
while count < 5:
print("Count:", count)
count += 1User Input Loop
while True:
answer = input("Type quit to exit: ")
if answer.lower() == "quit":
break
print("You typed:", answer)While vs For
- For loops — Known iteration count
- While loops — Unknown when to stop