A
while loop continues as long as a condition is true.
count = 0
while count < 5:
print(count)
count += 1
A while loop can run forever if the condition never becomes false:
# DANGER: Infinite loop!
while True:
print("This never stops!")
break: Exit the loop immediatelycontinue: Skip to the next iterationwhile True:
answer = input("Type 'quit' to exit: ")
if answer == "quit":
break
print(f"You typed: {answer}")
Interactive Visualization