While something stays true
A while loop repeats for as long as its condition is true. You are responsible for changing something inside, or it never ends.
count = 1
while count <= 3:
print(count)
count = count + 1 # or count += 1
print("Done")
for or while?
Use for when you know the items or how many times. Use while when you are waiting for a condition — until a total passes a limit, until the value reaches zero.
break and continue
break leaves the loop immediately; continue skips the rest of this round and starts the next.
number = 0
while True:
number += 1
if number == 4:
break
print(number) # 4
If a loop never ends, the tab freezes — always check that the value your condition tests actually changes. The code practice here runs in a sandbox with a time limit for exactly that reason.