0% found this document useful (0 votes)
5 views

Python break statement - Tutorialspoint1

The Python break statement is used to terminate the current loop and resume execution at the next statement, applicable in both while and for loops. It is particularly useful for exiting loops based on external conditions, and in nested loops, it only stops the innermost loop. The document provides syntax and examples demonstrating its usage in Python code.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Python break statement - Tutorialspoint1

The Python break statement is used to terminate the current loop and resume execution at the next statement, applicable in both while and for loops. It is particularly useful for exiting loops based on external conditions, and in nested loops, it only stops the innermost loop. The document provides syntax and examples demonstrating its usage in Python code.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1/9/2021 Python break statement - Tutorialspoint

Python break statement

It terminates the current loop and resumes execution at the next statement, just like the traditional
break statement in C.
The most common use for break is when some external condition is triggered requiring a hasty exit
from a loop. The break statement can be used in both while and for loops.
If you are using nested loops, the break statement stops the execution of the innermost loop and
start executing the next line of code after the block.

Syntax

The syntax for a break statement in Python is as follows −

break

Flow Diagram

Example

Live Demo
#!/usr/bin/python

https://www.tutorialspoint.com/python/python_break_statement.htm 1/2
1/9/2021 Python break statement - Tutorialspoint

for letter in 'Python': # First Example


if letter == 'h':
break
print 'Current Letter :', letter

var = 10 # Second Example


while var > 0:
print 'Current variable value :', var
var = var -1
if var == 5:
break

print "Good bye!"

When the above code is executed, it produces the following result −

Current Letter : P
Current Letter : y
Current Letter : t
Current variable value : 10
Current variable value : 9
Current variable value : 8
Current variable value : 7
Current variable value : 6
Good bye!

https://www.tutorialspoint.com/python/python_break_statement.htm 2/2

You might also like