Home »
Python »
Python programs
Python | Demonstrate an Example of break statement
Python break statement example: Here, we are going to learn how to use break statement in the loops in Python?
Submitted by Pankaj Singh, on October 06, 2018
break is a keyword in python just like another programming language and it is used to break the execution of loop statement.
In the given example, loop is running from 1 to 10 and we are using the break statement if the value of i is 6. Thus when the value of i will be 6, program's execution will come out from the loop.
Example 1:
for i in range(1,11):
if(i==6):
break
print(i)
Output
1
2
3
4
5
Example 2: In this example, we are printing character by character of the value/string “Hello world” and terminating (using break), if the character is space.
for ch in "Hello world":
if ch == " ":
break
print(ch)
Output
H
e
l
l
o
Python Basic Programs »
ADVERTISEMENT
ADVERTISEMENT