Stop the loop when you find what you need:
for num in range(1, 100):
if num == 7:
print("Found 7!")
break
print(num)
# Prints: 1, 2, 3, 4, 5, 6, Found 7!
Skip certain items without stopping:
for num in range(1, 6):
if num == 3:
continue # Skip 3
print(num)
# Prints: 1, 2, 4, 5
# Skip invalid data
scores = [85, -1, 92, 78, -1, 95]
for score in scores:
if score < 0:
continue # Skip invalid scores
print(f"Valid score: {score}")
Interactive Visualization