3 min read
break / continue
Prerequisites: for loops, while loops
break exits a loop immediately. continue skips the rest of the
current iteration and moves to the next one.
for number in range(10):
if number == 5:
break # stop the loop entirely
if number % 2 == 0:
continue # skip even numbers, keep looping
print(number)
Expected output
1
3