Linux

Python continue & pass Statement

The Python continue statement is used to skip the current iteration. Loop does not terminate but continues on with the next iteration.

Let's discuss with example.
avengers = ['hulk', 'iron-man', 'loki', 'Captain', 'Thor']
We are discussing about mightiest heroes, the Avengers.
I have the list of our heroes of the Avengers. But list contain the loki and i don't want to print loki.
Syntax of continue statement is very simple
continue
Let's understand the working of continue by examples.
Python continue statement
Python continue statement
Click to view code
So "loki" has not been printed, due to continue statement.

Consider a scenario, where you want to reserve a loop for future use. You don't want to write any thing in loop but they cannot have an empty body. So, we use the pass statement to construct a body that does nothing.
Syntax of pass
pass
Example
Python continue statement
Python continue statement
Click to view code










admin