Difference between pass and continue in Python

This article is created to clear all your doubts on the two conditional statements of the Python language, which are pass and continue.

The table given below differentiates "pass" and "continue" statements in the Python programming language.

pass continue
does nothing jumps for the next iteration
required when syntactically necessary but practically not required when you want to skip the execution of the remaining statement(s) inside the loop for the current iteration
can be used as a placeholder for future code can not be used as a placeholder for future code

pass vs. continue example in Python

Examples are extremely useful in understanding the topic of any computer programming language, such as Python. Therefore, here also, I've created an example that easily shows you the difference between these two statements:

nums = [1, 2, 3, 4, 5]

print("----Using \"pass\"-------")
for n in nums:
    if n == 3:
        pass
    print(n)

print("----Using \"continue\"-------")
for n in nums:
    if n == 3:
        continue
    print(n)

This program produces the following output:

pass vs continue python

As you can see from the above output, the pass statement does nothing, whereas the continue statement skips the execution of the remaining statements; that is, "continue" jumps for the next iteration, whereas "pass" does not.

Advantages of the pass statement in Python

Disadvantages of the pass statement in Python

Advantages of the continue statement in Python

Disadvantages of the continue statement in Python

Python Online Test


« Previous Tutorial Next Tutorial »