PYTHON Tutorial



BREAK, CONTINUE & PASS


🔄 Break, Continue, and Pass in Python

In Python, break, continue, and pass are used to control the flow of loops. They allow you to alter the normal sequence of execution in a loop.

🔸 Break Statement

The break statement is used to exit the current loop prematurely when a specified condition is met.

# Using break to stop the loop
for i in range(10):
    if i == 5:
        break
    print(i)
# Output: 0, 1, 2, 3, 4
  

🔸 Continue Statement

The continue statement is used to skip the current iteration of the loop and proceed with the next iteration.

# Using continue to skip the current iteration
for i in range(10):
    if i == 5:
        continue
    print(i)
# Output: 0, 1, 2, 3, 4, 6, 7, 8, 9
  

🔸 Pass Statement

The pass statement is a null operation. It serves as a placeholder in a block where code is syntactically required but you don't want to execute anything.

# Using pass when no action is needed
for i in range(10):
    if i == 5:
        pass  # No action performed for i == 5
    print(i)
# Output: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
  
💡 Note: - The break statement ends the loop entirely. - The continue statement skips the rest of the current iteration and moves to the next one. - The pass statement does nothing and is often used as a placeholder in loops, functions, or classes.

🌟 Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review