We Offer 100% Job Guarantee Courses (Any Degree / Diploma Candidates / Year GAP / Non-IT / Any Passed Outs). Placement Records
Hire Talent (HR):+91-9707 240 250

General

Python Break Continue

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
  • continue

Break Statement in Python

Break Statement in Python is used to terminate the loop.

Syntax of break Statement
Break;

Flow Chart of Break Statements

Flowchart of Break Statement in Python

 

Example 1 of break statement :

for i in range(10):
print(i)
if(i == 7):
print('break');
break

Output:-

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

Output:-

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
Continue;

Flowchart of continue Statement

Flowchart of Continue Statement in Python

Example of continue statement

for i in range(6):
if(i==3):
continue
print(i)

Output :-

0
1
2
4
5

Click Here-> Get Python Training with Real-time Projects

Besant Technologies WhatsApp