metinsaylan
metinsaylan
As an Amazon Associate, I earn from qualifying purchases.
  1. Home
  2. How To
  3. Snippets

How to Continue a Loop in Python

Staff // (Updated: )

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 ;)

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

More How To
Share Share Tweet