This article is created to clear all your doubt on the two conditional statements of Python language, that are pass and continue statement. I'm sure, after understanding all the things provided here, you'll get the complete knowledge about these two statements or keywords.
The table given below differentiates pass and continue statements of Python programming language:
|does nothing||jumps for next iteration|
|required when syntactically needed but practically not||required when want to skip the execution of remaining statement(s) inside the loop for current iteration|
|can be used as a placeholder for future code||can not be used as a placeholder for future code|
Example helps a lot in understanding the topic of any computer programming language like 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 following output:
As you can see from the above output, the pass statement does nothing, whereas the continue statement skip the execution of remaining statement, that is, continue jumps for the next iteration, whereas pass does not.
© Copyright 2021. All Rights Reserved.