break
Statement
The break
statement immediately stops the loop and exits out of it, even if the loop condition is still true.
Example:
for i in range(10):
if i == 5:
break
print(i)
Output:
0
1
2
3
4
Explanation:
When i
reaches 5
, the break
statement is triggered and the loop ends.
continue
Statement
The continue
statement skips the current iteration and goes to the next one.
Example:
for i in range(5):
if i == 2:
continue
print(i)
Output:
0
1
3
4
Explanation:
When i == 2
, the continue
skips that iteration and goes to i == 3
.
pass
Statement
The pass
statement does nothing. It's a placeholder when a statement is syntactically required but you don't want to write any code yet.
Example:
for i in range(3):
if i == 1:
pass # placeholder for future code
print(f"Processing {i}")
Output:
Processing 0
Processing 1
Processing 2
Explanation:
pass
does nothing — it's often used in places where you plan to add code later (e.g., empty functions or conditionals).
✅ Summary Table
Statement | Action |
---|---|
break |
Exits the loop entirely |
continue |
Skips to the next iteration of the loop |
pass |
Does nothing; used as a placeholder |
At Online Learner, we're on a mission to ignite a passion for learning and empower individuals to reach their full potential. Founded by a team of dedicated educators and industry experts, our platform is designed to provide accessible and engaging educational resources for learners of all ages and backgrounds.
Terms Disclaimer About Us Contact Us
Copyright 2023-2025 © All rights reserved.