Concept
Escaping Loops (break)
The `break` statement instantly terminates the entire loop:
python
for item in ["safe1", "virus", "safe2"]:
if item == "virus":
print("Threat found! Halting!")
break
print("Checking:", item)
# 60. Escaping Loops (break) The `break` statement instantly terminates the entire loop: ```python for item in ["safe1", "virus", "safe2"]: if item == "virus": print("Threat found! Halting!") break print("Checking:", item) ``` The moment Python hits `break`, it abandons all remaining turns and catapults straight out of the loop.
Checkpoint
What happens to the remaining loop turns when `break` fires?
Practice
Loop over `numbers = [1, 2, 3, 99, 4, 5]`. If a number equals `99`, `break` immediately. Print each number visited.
01
Tap code blocks below to assemble
Available Blocks