top of page

Break Statement in Python with example

Updated: Feb 17, 2022


The break statement is used to terminate the loop when a certain condition is gathering. The break statement is usually used inside a loop along with a if statement so that when a exacting condition returns true, the break statement is encountered and the loop terminates.

Syntax:

break

Flow Chart:



Example:

Program to display all the elements before number 70

for n in [11, 70, 88, 10, 90, 3, 7]:

print(n)

if(n==70):

print("The number 70 is found")

print("Terminating the loop")

break

Output:

11

70

The number 70 is found

Terminating the loop

Program:

x=0

while x<=15:

print("x value : ",x)

if x==3:

break

x=x+1

Output:

x value : 0

x value : 1 x value : 2

x value : 3


Break Statement Video:





19 views0 comments

Recent Posts

See All

Tell () function can be used to get the position of file handle and returns current position of file object where as Seek () function is used to change the position of the file handle to a given speci

Seek () function is used to change the position of the file handle to a given specific position in python. File handle such as a cursor which defines from where the data has to be read or written in t

bottom of page