The main difference between Python for loop continue vs pass is
pass simply does nothing, while
continue goes on with the next loop iteration.
continue forces the loop to start at the next iteration while
pass means “there is no code to execute here” and will continue through the remainder of the loop body.
Python for loop continue vs pass
A simple example code difference would become apparent if you added another statement after the
if: After executing
pass, this further statement would be executed. After
continue, it wouldn’t.
a = [0, 1, 2] for element in a: if not element: print('Pass') pass print(element) for element in a: if not element: print('Continue') continue print(element)
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.
As the name suggests pass statement simply does nothing. We use pass statements to write empty loops. Pass is also used for empty control statements, functions, and classes.
Do comment if you have any doubts or suggestions on this Python continue vs pass topic.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.