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:

  1. break
  2. continue
  3. 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

PYTHON
1for i in range(1, 6):
2 if i == 3:
3 break
4 print(i)
▶ Output will appear here.

The loop stops when i becomes 3.

Example 2: Using break in a while Loop

PYTHON
1count = 1
2while count <= 5:
3 if count == 4:
4 break
5 print(count)
6 count += 1
▶ Output will appear here.

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:

PYTHON
1for i in range(1, 6):
2 if i == 3:
3 continue
4 print(i)
▶ Output will appear here.

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

PYTHON
1for i in range(5):
2 pass # loop runs, but does nothing
3print("Loop finished")
▶ Output will appear here.

More Python tutorials

All tutorials · Try the free PySpark compiler · Practice challenges