The continue statement helps skip the rest of the current loop step and move to the next one. It lets you ignore certain cases without stopping the whole loop.
0
0
Continue statement behavior in Python
Introduction
When you want to skip processing some items in a list but keep looping through the rest.
When filtering data inside a loop and ignoring unwanted values.
When you want to avoid nested if-else blocks by skipping early.
When reading lines from a file and ignoring empty or comment lines.
When you want to jump to the next iteration after a condition is met.
Syntax
Python
continueThe continue statement is used inside loops like for or while.
When Python sees continue, it skips the rest of the current loop step and starts the next one immediately.
Examples
This loop prints numbers 0 to 4 but skips printing 2 because of
continue.Python
for i in range(5): if i == 2: continue print(i)
This
while loop skips printing 3 but prints other numbers from 1 to 5.Python
i = 0 while i < 5: i += 1 if i == 3: continue print(i)
Sample Program
This program prints numbers from 1 to 5 but skips number 3 using continue.
Python
for number in range(1, 6): if number == 3: continue print(f"Number is {number}")
OutputSuccess
Important Notes
Using continue can make your loops cleaner by avoiding deep nesting.
Be careful not to create infinite loops when using continue inside while loops without updating the loop variable.
Summary
continue skips the rest of the current loop step and moves to the next.
It works inside for and while loops.
Use it to ignore certain cases without stopping the whole loop.