Python break statement


  Translation results:

The Python break statement, like in C, breaks the smallest enclosing for or while loop.

The break statement is used to terminate the loop statement. That is, if the loop condition does not have a False condition or the sequence has not been completely recursed, the execution of the loop statement will also be stopped.

The break statement is used in while and for loops.

If you use nested loops, the break statement stops execution of the deepest loop and begins executing the next line of code.

Python break statementsyntax

The Python break statement, like in C, breaks the smallest enclosing for or while loop.

The break statement is used to terminate the loop statement. That is, if the loop condition does not have a False condition or the sequence has not been completely recursed, the execution of the loop statement will also be stopped.

The break statement is used in while and for loops.

If you use nested loops, the break statement stops execution of the deepest loop and begins executing the next line of code.

Python break statementexample

#!/usr/bin/python# -*- coding: UTF-8 -*-
for letter in 'Python': # first instance
if letter == 'h': break
print 'Current letter:', letter
var = 10
Print 'Current variable value:', var
var = var -1
if var == 5: # Exit the loop when variable var equals 5
break
print "Good bye!"

Popular Recommendations

Home

Videos

Q&A