Using loops in Python automates and repeats the tasks in an efficient manner. But sometimes, there may arise a condition where you want to exit the loop completely, skip an iteration or ignore that condition. These can be done by loop control statements. Loop control statements change execution from its normal sequence. When execution leaves a scope, all automatic objects that were created in that scope are destroyed. Python supports the following control statements.
In this article, the main focus will be on the difference between
This statement is used to skip over the execution part of the loop on a certain condition. After that, it transfers the control to the beginning of the loop. Basically, it skips its following statements and continues with the next iteration of the loop.
As the name suggests pass statement simply does nothing. We use pass statement to write empty loops. Pass is also used for empty control statements, functions and classes.
Difference between continue and pass
Consider the below example for better understanding the difference between continue and pass statement.
g e e Pass executed k s g e e Continue executed s
In the above example, when the value of
i becomes equal to ‘
k‘, the pass statement did nothing and hence the letter ‘
k‘ is also printed. Whereas in the case of continue statement, the continue statement transfers the control to the beginning of the loop, hence the letter
k is not printed.
- Loops and Control Statements (continue, break and pass) in Python
- break, continue and pass in Python
- Python Continue Statement
- Python pass Statement
- Pass by reference vs value in Python
- How to pass argument to an Exception in Python?
- Python - pass multiple arguments to map function
- Different Forms of Assignment Statements in Python
- How to write an empty function in Python - pass statement?
- Pass list as command line argument in Python
- Python | Split and Pass list as separate parameter
- PyQt5 QCalendarWidget - Continue functions by enabling
- How to pass multiple arguments to function ?
- Python3 - if , if..else, Nested if, if-elif statements
- Python set operations (union, intersection, difference and symmetric difference)
- Difference between 'and' and '&' in Python
- Difference between Python and C++
- Python Set | difference()
- Difference Between x = x + y and x += y in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai