Continue statement is a loop control statement, that is used when you want to skip the loop for a certain condition and continue iterating python for loop with the next item on the list. Continue statement doesn’t break the loop. Instead continue skips only current item in the loop and switches list iterator to the next item in the list.

Continue statement must be used inside a loop (for, while) block. It is often used after an if conditional statement.


Using Continue Statement In Python

Here is a sample code snippet demonstrating usage of continue statement in Python:

for fruit in ["apple", "banana", "kiwi", "strawberry"]:

   if fruit == "banana":
      continue    # skip this item

   print('I <3 ' + fruit)

print('The end.')

This sample code snippet outputs the following:

I <3 apple
I <3 kiwi
I <3 strawberry
The end.

Note that, python skip the banana item on the list using the for loop continue operator.

I hope you liked this tip. Don’t forget to follow me on twitter for more tips like this ;)