Class 9 Exam  >  Class 9 Notes  >  Python break statement

Python break statement - Class 9 PDF Download

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).

Python break statement - Class 9

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

The document Python break statement - Class 9 is a part of Class 9 category.
All you need of Class 9 at this link: Class 9

Top Courses for Class 9

Download as PDF
Explore Courses for Class 9 exam

Top Courses for Class 9

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

study material

,

MCQs

,

shortcuts and tricks

,

mock tests for examination

,

Semester Notes

,

Extra Questions

,

practice quizzes

,

Python break statement - Class 9

,

ppt

,

Summary

,

past year papers

,

Viva Questions

,

Important questions

,

video lectures

,

Exam

,

Previous Year Questions with Solutions

,

Python break statement - Class 9

,

Free

,

Python break statement - Class 9

,

pdf

,

Sample Paper

,

Objective type Questions

;