How to Skip the Rest of a Loop Turn in Python with continue
Inside a loop, some items shouldn't be processed: an empty line, a blank answer. continue skips the rest of the current turn and moves on to the next item, so the code that follows doesn't need to sit inside an if. This guide skips empty strings, with real output from Python 3.15.2.
Syntax
for <item> in <iterable>:
if <condition>:
continue
<code for the items you keep>
| Part | What it means |
|---|---|
if <condition>: | The check that decides to skip |
continue | Ends this turn now and starts the next one |
| The code below | Runs only for items that weren't skipped |
continue works the same in a while loop. Python's language reference: "continue may only occur syntactically nested in a for or while loop, but not nested in a function or class definition within that loop. It continues with the next cycle of the nearest enclosing loop."
Prerequisites
- uv and Python. This guide uses uv 0.13.10 with Python 3.15.2, in a project made with
uv init.
Step 1: Write the Script
for word in ["apple", "", "pear", "", "plum"]:
if not word:
continue
print(word.upper())

not word is true for an empty string.
Step 2: Run It
uv run python skip_empty.py
APPLE
PEAR
PLUM

The loop ran five times but printed three lines: on the two empty strings, continue skipped the print().
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Using continue outside a loop | SyntaxError: 'continue' not properly in loop | Use it only inside for or while |
Using break when you meant continue | The loop ends at the first empty string | continue skips one turn; break ends the loop |
In a while loop, updating the counter below continue | The counter never changes, and the loop repeats forever | Update it before continue |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Items you expected are missing | The skip condition is too broad | Print the items the condition skips, then narrow it |
FAQ
Is continue better than wrapping the code in an if?
It keeps the main code unindented, which helps when several checks come before it. For a single short check, an if reads just as well.
Does continue skip the loop's else block?
No. A loop's else runs when the loop finishes without break, whether or not continue was used.
Conclusion
On the two empty strings, continue jumped to the next item, so the loop printed only APPLE, PEAR and PLUM.
Additional Resources
- The continue statement — skipping to the next turn of a loop.
