Programming with Python

  1. Home
  2. Docs
  3. Programming with Python
  4. Control statement in python
  5. Use of break in python

Use of break in python

The break statement enables a program to skip over a part of the code. A break statement terminates the very loop it lies within.

syntax where we use for loop and break:-

for variable in sequence:
    statement1
    if expression:
       break
    statement2
statement3

syntax where we use while loop and break:-

while expression1:
    statement1
    if expression2:
        break
    statement2
statement3

e.g.,

for a in "python":
    if a == "h":
        break
    print(a)
Output-
p
y
t

This is all about break in python.

Was this article helpful to you? Yes No

How can we help?