All courses › Programming with Python › break and continue
break and continue
break ends the loop immediately, while continue just skips to the next round and keeps the loop going. Both are typically used with an if condition inside the loop to handle special cases.
ends the whole loop immediately
skips the rest of the round, loop continues
Example
for i in range(3): pass
print(i) prints 2, since the loop variable keeps its last value after the loop.
break leaves the loop, continue stays in it — do not mix them up.