Python Break Continue
Python Jump Statements (break, continue and pass)
Jump statements in python are used to alter the flow of a loop like you want to skip a part of a loop or terminate a loop.
Type of Jump Statements in Python
Break Statement in Python
Break Statement in Python is used to terminate the loop.
Syntax of break Statement
Flow Chart of Break Statements
Example 1 of break statement :
for i in range(10): print(i) if(i == 7): print('break'); break
0 1 2 3 4 5 6 7 break
Example 2 of break statement
After break statement controls goes to next line pointing after the loop body.
for i in range(10): print(i) if(i == 7): print('before break') break print('after break') # Inside loop body, any code after the break statement will not execute print('Out of loop body')
0 1 2 3 4 5 6 7 before break Out of loop body
Continue Statement in Python
Continue Statement in Python is used to skip all the remaining statements in the loop and move controls back to the top of the loop.
Syntax of continue Statement
Flowchart of continue Statement
Example of continue statement
for i in range(6): if(i==3): continue print(i)
0 1 2 4 5
Click Here-> Get Python Training with Real-time Projects