Try it here
Subscribe
Break , continue and pass

Break , continue and pass keywords in python

break_,_continue_and_pass_keywords_in_python

Break

Break allows loop termination when some condition is met and the control is transferred to the next statement.

Example:

>>> for i in range(9):
	if i==3:
		break
	else:
		print(i)

		
0
1
2
>>> 

Continue

Continue allows skipping some part of a loop when some specific condition is met and the control is transferred to the beginning of the loop

Example:

>>> for i in range(3):
	if i==1:
		continue
	else:
		print(i)

		
0
2
>>> 

Pass

Pass is used when you need some block of code syntactically, but you want to skip its execution. This is basically a null operation. Nothing happens when this is executed.

Example:

>>> for i in range(3):
	pass

>>> 

Writer profile pic

Prakash on Apr 21, 2020 at 12:04 am


This article is contributed by Prakash. If you like dEexams.com and would like to contribute, you can write your article here or mail your article to admin@deexams.com . See your article appearing on the dEexams.com main page and help others to learn.



Post Comment

Comments( 0)

WEB TECHNOLOGY

Articles

×

Forgot Password

Please enter your email address below and we will send you information to change your password.