🚀 Supercharge your YouTube channel's growth with AI.
Try YTGrowAI Free
The continue statement syntax is:
continue
We canโt use any option, label or condition with the continue statement.
Let’s look at some examples of using the continue statement in Python.
Let’s say we have a sequence of integers. We have to skip processing if the value is 3. We can implement this scenario using for loop and continue statement.
t_ints = (1, 2, 3, 4, 5)
for i in t_ints:
if i == 3:
continue
print(f'Processing integer {i}')
print("Done")
Output:

Here is a simple example of using continue statement with the while loop.
count = 10
while count > 0:
if count % 3 == 0:
count -= 1
continue
print(f'Processing Number {count}')
count -= 1
Output:

Let’s say we have a list of tuples to process. The tuple contains integers. The processing should be skipped for below conditions.
We can implement this logic with nested for loops. We will have to use two continue statements for implementing above conditions.
list_of_tuples = [(1, 2), (3, 4), (5, 6, 7)]
for t in list_of_tuples:
# don't process tuple with more than 2 elements
if len(t) > 2:
continue
for i in t:
# don't process if the tuple element value is 3
if i == 3:
continue
print(f'Processing {i}')
Output:

Many popular programming languages support a labeled continue statement. Itโs mostly used to skip the iteration of the outer loop in case of nested loops. However, Python doesnโt support labeled continue statement.
PEP 3136ย was raised to add label support to continue statement. But, it was rejected because it’s a very rare scenario and it will add unnecessary complexity to the language. We can always write the condition in the outer loop to skip the current execution.