Python Control Statements

Introduction

The loop control statements are used to interrupt the normal execution of sequence. Python supports below control statements:

TypesDescription
breakIt is used to terminate the further loop execution and transfers the control to immediate next statement following the loop.
continueIt skips the further execution of the  statements of the loop body and resets it condition.
passIt is used where code is required syntactically but the execution is not required.

 

Example

1.      Break statement

 

n = 10

for val in range(0, n):

if val == 5 or val == 10:

break

print(val)

 

Output:

0
1
2
3
4

2.      Continue statement

n = 10

for val in range(0, n):

if val == 5:

continue

print(“Example of continue control statement!”)

 

Output:

Example of continue control statement!

3.      Pass statement

 

for val in ‘gocoding’:

pass

print(‘Last letter’,val)

 

Output:

Last letter g

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.