After completing this chapter, you will be able to:
- Understand Jump Statements in Python.
- Explain why Jump Statements are used.
- Learn the
break,continue, andpassstatements. - Understand the execution flow of each jump statement.
- Write programs using Jump Statements.
- Differentiate between
break,continue, andpass.
During the execution of loops, there are situations where we need to:
- Stop the loop immediately.
- Skip the current iteration.
- Keep a placeholder for future implementation.
Python provides Jump Statements to perform these tasks.
The three Jump Statements in Python are:
breakcontinuepass
Jump Statements are control statements that alter the normal flow of program execution by terminating a loop, skipping an iteration, or acting as a placeholder.
Jump Statements
│
├── break
├── continue
└── pass
The break statement immediately terminates the loop and transfers control to the first statement after the loop.
The break statement is used when:
- The required result is found.
- An error condition occurs.
- No further iterations are required.
for variable in sequence:
if condition:
breakLoop Starts
│
▼
Condition
│
True ─────► break
│
False
│
Continue Loop
│
Loop Ends
Write a Python program to print numbers from 1 to 10 and stop when the number becomes 6.
# Print numbers using for loop
for number in range(1, 11):
# Check the condition
if number == 6:
break
# Display number
print(number)1
2
3
4
5
- The loop starts from 1.
- Numbers 1 to 5 are printed.
- When the value becomes 6, the
breakstatement terminates the loop.
The continue statement skips the current iteration and transfers control to the next iteration of the loop.
The continue statement is used when:
- A particular value should be skipped.
- Certain conditions should be ignored.
- Processing should continue with the remaining values.
for variable in sequence:
if condition:
continueLoop Starts
│
▼
Condition
│
True
│
continue
│
Next Iteration
│
False
│
Execute Statements
Write a Python program to print numbers from 1 to 10 except 6.
# Print numbers using for loop
for number in range(1, 11):
# Skip number 6
if number == 6:
continue
# Display number
print(number)1
2
3
4
5
7
8
9
10
- Numbers 1 to 10 are processed.
- When the value becomes 6,
continueskips that iteration. - Remaining numbers are printed.
The pass statement is a null statement.
It does nothing when executed.
It is used as a placeholder where code will be added later.
The pass statement is used:
- During program development.
- When writing empty functions.
- When creating empty classes.
- When writing empty loops.
if condition:
passWrite a Python program demonstrating the use of the pass statement.
# Check a condition
number = 10
if number > 5:
pass
print("Program Executed Successfully")Program Executed Successfully
- The
passstatement performs no action. - Program execution continues normally.
| Statement | Purpose | Effect |
|---|---|---|
break |
Terminates the loop | Exits the loop completely |
continue |
Skips the current iteration | Continues with the next iteration |
pass |
Placeholder statement | Performs no action |
- Search Operations
- Menu Exit
- Game Over Condition
- Skip Invalid Records
- Ignore Empty Input
- Skip Specific Values
- Empty Functions
- Empty Classes
- Future Code Implementation
- Improves control over loop execution.
- Reduces unnecessary processing.
- Simplifies program logic.
- Improves readability.
- Supports structured program development.
❌ Incorrect
breakThis produces a SyntaxError.
❌ Incorrect
continueThis also produces a SyntaxError.
Remember:
pass→ Does nothing.continue→ Skips the current iteration.
Jump Statements are control statements that alter the normal flow of execution.
The break statement immediately terminates the loop.
The continue statement skips the current iteration and continues with the next iteration.
The pass statement is a placeholder that performs no operation.
No.
Using break outside a loop results in a SyntaxError.
No.
Using continue outside a loop also results in a SyntaxError.
No.
The pass statement does not affect program execution.
breakterminates the loop.continueskips the current iteration.passperforms no action.breakandcontinueare used only inside loops.passis commonly used as a placeholder.
In this chapter, you learned:
- What Jump Statements are.
- The
breakstatement. - The
continuestatement. - The
passstatement. - Syntax and execution flow.
- Practical programs.
- Real-world applications.
- Differences between
break,continue, andpass. - Common mistakes.
- Interview questions.