Break, Continue and Pass
These are special statements that alter loop behavior:
break
– Exits the loop completely.continue
– Skips the current iteration and moves to the next.pass
– Does nothing (used as a placeholder).
Examples
for i in range(5):
if i == 3:
break
print(i) # Prints 0, 1, 2
for i in range(5):
if i == 2:
continue
print(i) # Skips 2
for i in range(5):
if i == 4:
pass # Placeholder
print(i)