Using loops in Python automates and repeats the tasks in an efficient manner. But sometimes, there may arise a condition where you want to exit the loop completely, skip an iteration or ignore that condition. These can be done by loop control statements. Loop control statements change execution from its normal sequence. When execution leaves a scope, all automatic objects that were created in that scope are destroyed. Python supports the following control statements.
- Continue statement
- Break statement
- Pass statement
In this article, the main focus will be on break statement.
Break statement
Break statement in Python is used to bring the control out of the loop when some external condition is triggered. Break statement is put inside the loop body (generally after if condition).

Syntax:
break
Example:
# Python program to # demonstrate break statement s = 'geeksforgeeks'# Using for loop for letter in s: print(letter) # break the loop as soon it sees 'e' # or 's' if letter == 'e' or letter == 's': break print("Out of for loop") print() i = 0 # Using while loop while True: print(s[i]) # break the loop as soon it sees 'e' # or 's' if s[i] == 'e' or s[i] == 's': break i += 1 print("Out of while loop") |
Output:
g e Out of for loop g e Out of while loop
In the above example, both the loops are iterating the string ‘geeksforgeeks’ and as soon as they encounter the character ‘e’ or ‘s’, the if condition becomes true and the flow of execution is brought out of the loop.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- Loops and Control Statements (continue, break and pass) in Python
- Break a list into chunks of size N in Python
- Python | Group elements on break positions in list
- break, continue and pass in Python
- Create a Python Script Notifying to take a break
- How to write an empty function in Python - pass statement?
- Using else conditional statement with for loop in python
- Statement, Indentation and Comment in Python
- with statement in Python
- Python return statement
- Python Continue Statement
- Check multiple conditions in if statement - Python
- Nested-if statement in Python
- Python pass Statement
- Important differences between Python 2.x and Python 3.x with examples
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Sort Python Dictionaries by Key or Value
- Python | Merge Python key values to list
- Reading Python File-Like Objects from C | Python
- Python | Add Logging to a Python Script
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

