Python: pass Loop Control Statement


The flow inside looping statements are controlled using the looping control statements like pass, break and continue.

In python, pass is a null statement which is used to do create empty blocks. When pass is executed, it results in no operation and the control will move to the next statement applicable.

Example

Below example program shows how pass can be used to create a empty if block.

num=10
count=0
while(count <= num):
   if(count%2 == 0):
	  pass
   else:
	  print(count)
   count+=1

Output

1
3
5
7
9

In the above example try to explain the case of pass statement and treat as empty block. Otherwise same case be handle through continue with same result.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s