Python has some reserved words known as keywords that the Python interpreter recognizes.
continue are some of the keywords found in the Python programming language. Interestingly, some keywords are primarily used in standard settings, so their purpose is mistaken.
continue are mostly used inside
else statements and inside
for loops and
return is used inside functions, and sometimes, we can also find the
One such pair of keywords is
continue. They are found inside loops and conditional statements. Their behavior is sometimes mistaken to be the same.
This article will discuss the difference between
continue keywords in Python.
continue Keywords in Python
pass keyword in Python is a
null statement. When a Python interpreter lands on this statement, it parses it, but nothing happens.
Generally, developers and programmers use it as a placeholder for code they plan to write in the near future.
Many people think that the
pass statement is ignored by a Python interpreter, like comments (statements starting with an
#), but that is not true. A Python interpreter knows that no operation must be performed for the
continue keyword or statement stops the execution of the following code for an iteration. Any code that follows the
continue statement does not get executed. A Python interpreter jumps to the next iteration.
continue statement is used when a programmer or a developer wishes to perform no action for a blocklisted condition.
Let us understand these two statements with the help of some examples. Refer to the following Python code for the
for i in range(10): if i % 2 == 0: pass print(i)
0 1 2 3 4 5 6 7 8 9
From the output, we can understand that the iteration number will get printed even after the
pass statement is present inside the
if statement. As mentioned above, a Python interpreter will perform no action when it encounters a
Refer to the following Python code for the
for i in range(10): if i % 2 == 0: continue print(i)
1 3 5 7 9
From the output, we can infer that the code after the
continue statement, no matter if it is inside the same conditional statement block or not, will strictly not get executed. A Python interpreter will shift to the next iteration after discovering the