Python Continue Statement
Python continue statement is used to skip further instruction in the loop for that iteration.
In this tutorial, we shall see example programs to use continue statement with different looping statements.
Following is the syntax of continue statement.
Just the continue keyword in the line and nothing else.
Example 1: Continue Statement with While Loop
In this example, we shall write a while loop to print numbers from 1 to 10. When when the loop is running to print 4 or 7, we shall conditionally execute continue statement.
i = 1 while i <= 10 : if i == 4 or i==7 : i += 1 continue print(i) i += 1
Please note that, we have taken care of updating loop control variable
i before executing continue statement.
1 2 3 5 6 8 9 10
Example 2: Continue Statement with For Loop and Range
In this example, we shall continue the execution of for loop when the element is divisible by
for x in range(1, 11) : if x%3 == 0 : continue print(x)
1 2 4 5 7 8 10
Example 3: Break Statement with For Loop and List
In this example, we shall iterate over list using for loop. When we get an element of
9, we shall continue with next elements.
myList = [9, 1, 5, 9, 4, 9, 7, 2, 9] for x in myList : if x == 9: continue print(x)
1 5 4 7 2
In this tutorial of Python Examples, we learned how to use continue statement to skip the execution of further statements during that iteration and continue with next iterations or elements in the collection.