Jump Statements
Python tutorial · PySpark.in
Jump Statements (Transfer of Control) in Python
In Python, Jump Statements are used to change the normal flow of program execution.They are especially useful when working with loops or conditional blocks, allowing you to exit early,skip iterations, or keep placeholders for future code.
Python provides three main jump statements:
- break
- continue
- pass
Break Statement
The break statement is used to terminate the loop immediately, even if the loop condition is still true.Once a break is encountered, control jumps out of the loop to the next statement after it.
Example 1: Using break in a for Loop
The loop stops when i becomes 3.
Example 2: Using break in a while Loop
Use case: When you need to exit a loop as soon as a specific condition is met.
Continue Statement
The continue statement skips the current iteration of a loop and moves to the next one.It does not terminate the loop completely — it just jumps to the next iteration.
Example:
Here, when i == 3, the loop skips printing 3 and continues with the next number.
Use case: When you want to ignore specific conditions but continue looping.
Pass Statement
The pass statement is a null operation — it does nothing.
It’s used as a placeholder when a statement is syntactically required but you don’t want to execute any code.
Example : Using pass in a Loop
More Python tutorials
- What is Python and Why is it used for Data Science and Data Engineering?
- How Does Python Work in the Backend? Internal Working of Python
- Top 30 Python Interview Questions for Data Science
- 3-Month Python Roadmap to Excel in Data Science and Machine Learning
- Python Data Types Explained – A Beginner’s Guide
- test
All tutorials · Try the free PySpark compiler · Practice challenges