Total Pageviews

Wednesday, September 9, 2026

Difference between break, continue and pass

Break, Continue and Pass in Python

Complete Tutorial with Syntax, Examples & Output

1. Introduction

In Python, break, continue and pass are special statements used to control the flow of a program.

These statements are especially important when working with for and while loops.

break

Stops the loop completely.

continue

Skips the current iteration.

pass

Does nothing.

break = STOP   |   continue = SKIP   |   pass = DO NOTHING

2. break Statement

The break statement is used to terminate a loop immediately.

Definition: The break statement terminates the nearest enclosing for or while loop.

Syntax

break

Example

for i in range(1, 11):

    if i == 6:
        break

    print(i)
Output:
1
2
3
4
5

When i becomes 6, the break statement is executed and the loop terminates.

3. How break Works

Loop Starts ↓ Condition Checked ↓ break encountered ↓ Loop Terminates ↓ Execution continues after loop

4. Practical Example of break

Suppose we want to search for a particular number in a list. Once the number is found, we can stop searching.

Example

numbers = [10, 20, 30, 40, 50]

for number in numbers:

    if number == 30:
        print("Number found")
        break
Output:
Number found

5. continue Statement

The continue statement skips the remaining statements of the current iteration and moves to the next iteration.

Definition: continue does not terminate the loop. It only skips the current iteration.

Syntax

continue

Example

for i in range(1, 11):

    if i == 6:
        continue

    print(i)
Output:
1
2
3
4
5
7
8
9
10

The value 6 is skipped, but the loop continues with the next iteration.

6. How continue Works

Loop Starts ↓ Condition Checked ↓ continue encountered ↓ Remaining statements skipped ↓ Next iteration ↓ Loop continues

7. Practical Example of continue

The following program uses continue to skip even numbers.

Example

for number in range(1, 11):

    if number % 2 == 0:
        continue

    print(number)
Output:
1
3
5
7
9

8. pass Statement

The pass statement is a null statement. It does not perform any operation.

Definition: pass is used as a placeholder when a programmer needs a statement syntactically but does not want to execute any action.

Syntax

pass

Example

for i in range(1, 6):

    if i == 3:
        pass

    print(i)
Output:
1
2
3
4
5

When i = 3, pass does nothing. Therefore, 3 is still printed.

9. Practical Example of pass

The pass statement is useful when a programmer wants to create a function but will implement it later.

Example

def calculate_result():
    pass

print("Program completed")
Output:
Program completed

10. Difference Between break, continue and pass

Statement Purpose Effect Loop Continues?
break Stop the loop Terminates the loop No
continue Skip iteration Moves to next iteration Yes
pass Do nothing No operation Yes

11. Comparing All Three Statements

Using break

for i in range(1, 6):

    if i == 3:
        break

    print(i)
Output:
1
2

Using continue

for i in range(1, 6):

    if i == 3:
        continue

    print(i)
Output:
1
2
4
5

Using pass

for i in range(1, 6):

    if i == 3:
        pass

    print(i)
Output:
1
2
3
4
5

12. break with while Loop

Example

i = 1

while i <= 10:

    if i == 5:
        break

    print(i)

    i += 1
Output:
1
2
3
4

13. continue with while Loop

Example

i = 0

while i < 5:

    i += 1

    if i == 3:
        continue

    print(i)
Output:
1
2
4
5
Important: When using continue in a while loop, make sure the loop-control variable is updated properly. Otherwise, an infinite loop can occur.

14. Real-Life Examples

Python Statement Real-Life Example
break You are searching for a book. Once you find it, you stop searching.
continue You are checking students. If one student is absent, you skip that student and check the next student.
pass A task has not been implemented yet, so you temporarily leave the block empty.

15. Important Examination Points

  • break terminates the nearest enclosing loop.
  • continue skips the current iteration.
  • pass performs no operation.
  • break does not move to the next iteration.
  • continue moves to the next iteration.
  • pass is commonly used as a placeholder.

16. Complete Comparison Table

Feature break continue pass
Terminates loop Yes No No
Skips current iteration No Yes No
Does nothing No No Yes
Next iteration No Yes Yes
Used in loops Yes Yes Yes
Used as placeholder No No Yes

17. Quick Memory Trick

BREAK → STOP THE LOOP

CONTINUE → SKIP THE CURRENT ITERATION

PASS → DO NOTHING

18. Summary

The break, continue, and pass statements are important Python control statements.

  • break: Completely terminates the loop.
  • continue: Skips the current iteration and proceeds to the next iteration.
  • pass: Performs no operation and is generally used as a placeholder.
break = STOP   |   continue = SKIP   |   pass = DO NOTHING

No comments:

Post a Comment