Nearby lessons

51 of 108

Python - Break Statement

Transfer Statements

Transfer statements are used to change the normal flow of program execution.

Python provides three transfer statements:

  • break
  • continue
  • pass

break Statement

The break statement is used to stop the loop immediately.

When Python executes the break statement, the loop terminates and control moves to the first statement after the loop.

Syntax

🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
No output captured.

Example 1 - break Statement

🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
0
1
2
3
4
5
6

Explanation

The loop starts from 0.

When i becomes 7, the break statement is executed.

The loop stops immediately.

Example 2 - break with while Loop

🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
1
2
3
4
5

Real World Usage of break

The break statement is commonly used in:

  • Search operations
  • Menu-driven programs
  • Password verification
  • Infinite loops that need an exit condition

Difference Between break and continue

break continue
Terminates the loop. Skips only the current iteration.
Control comes outside the loop. Control moves to the next iteration.
Remaining iterations are not executed. Remaining iterations continue normally.

🧠 Test Your Knowledge

2 Questions

Progress: 0 / 2
Keep Going!Python - Collection For Loop