Q:

Python | Demonstrate an Example of break statement

belongs to collection: Python basic programs

0

break is a keyword in python just like another programming language and it is used to break the execution of loop statement.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python basic programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Python | Demonstrate an Example of continue statem... >>
<< Python | Some of the Examples of loops...