Module 3
break
Stopping a loop early.
Leaving the loop
The break statement stops a loop immediately. The program continues with the code after the loop.
Python
for base in "ATGCGCA":
if base == "G":
print("Found G")
break→ Found G
The loop stops as soon as it finds the first G. The remaining characters are not visited.
Your task
Use break
- Loop through ATGCGCA and stop when you find G. Print Found G.