Skip to content

Continue statement in Python

Python Continue statement is used to skip the remaining statements of the current loop and go to the next iteration. It allows us to change the loop’s control.

continue

This is useful when you want to leave the current loop entirely, skip iteration, or dismiss the condition controlling the loop.

Continue statement in Python

A simple example code will execute a loop from 10 to 20 and test the condition that the iterator is equal to 15. If it equals 15, skip to the following iteration otherwise, the loop will print the result.

for i in range(10, 21):

    # If iterator is equals to 15
    if i == 15:
        print('Skip')
        continue
    print(i, end=' ')

Output:

Continue statement in Python
  • The continue statement is utilized to skip the current loop’s remaining statements, go to the following iteration, and return control to the beginning.
  • It takes the control back to the start of the loop.
  • It works with both Python while and Python for loops.
  • It’s mostly utilized within a loop’s condition.

Comment if you have any doubts or suggestions on this Python control statement topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading