Introduction
Infinite loops keep a program running forever, which can freeze your computer or app. Preventing them helps your program stop at the right time.
Jump into concepts and practice - no test required
while condition: # do something # update condition or use break to stop loop
count = 0 while count < 5: print(count) count += 1
while True: answer = input('Type exit to stop: ') if answer == 'exit': break
count = 0 while count < 3: print(f'Count is {count}') count += 1 print('Loop ended')
i = 0
while i < 3:
print(i)
i -= 1count = 5
while count > 0:
print(count)