Python continue Statement

In the last lesson you learned the break Statement. That one leaves a loop early and stops it for good. But sometimes you do not want to stop the whole loop. You just want to skip one item and keep going. That is exactly what continue is for.

πŸ€” Why Do We Need continue?

Say you are looping over a list of names. A few of them are blank. You do not want to process the blank ones. But you also do not want to end the loop. The blank ones are not the end of your data. They are just gaps you want to ignore.

Without continue, you would wrap the rest of your loop body in an if. Then you indent everything deeper. The more things you want to skip, the messier that gets.

The continue statement fixes this. It says skip the rest of this turn and move on to the next one. And it stays inside the loop the whole time.

🧩 What continue Actually Does

Here is the simple idea. A loop runs its body once for each item. When Python reaches continue, it stops the current turn right there. It does not run any lines below continue. Instead it jumps straight back to the top of the loop and grabs the next item.

Think of it like marking emails as read. You are going through your inbox one by one. You see a newsletter you do not care about. You do not delete the whole inbox, right? You just skip that email and look at the next one. continue is that skip.

The syntax is just one word on its own line. Usually it sits inside an if.

for item in items:
if some_condition:
continue
# this line is skipped when the condition is true
print(item)

When some_condition is true, Python hits continue and goes back to the top for the next item. The print line never runs for that item.

πŸ”’ A Real Example: Skip the Even Numbers

Let’s print only the odd numbers from 1 to 10. We loop over every number. But when a number is even, we skip it.

for number in range(1, 11):
if number % 2 == 0:
continue
print(number)

Reading it line by line:

  • range(1, 11) gives us the numbers 1 through 10.
  • number % 2 == 0 is true when the number divides evenly by 2. That means it is even.
  • When that is true, continue skips the rest of this turn. So the print below never runs.
  • For odd numbers the if is false. So we skip past continue and reach the print.

So only the odd numbers make it to the screen.

Output

1
3
5
7
9

Notice we never wrote an else. The continue handles the β€œbad” cases up top. That lets the rest of the loop body stay flat and easy to read.

πŸ“ A More Real Example: Skip Blank Entries

Now something closer to real work. Imagine you collected sign-up names from a form. Some rows came in empty. You want to greet each real person and quietly skip the blanks.

names = ["Alex", "", "Arjun", " ", "Maya"]
for name in names:
if name.strip() == "":
continue
print(f"Welcome, {name}!")

Here is what happens:

  • name.strip() removes spaces from both ends of the text.
  • If what is left is an empty string, the entry is really blank. So we continue and skip it.
  • A blank "" and a spaces-only " " both get skipped this way.
  • Real names fall through to the print and get a welcome message.

Output

Welcome, Alex!
Welcome, Arjun!
Welcome, Maya!

The two empty rows simply never reach the print. The loop did not stop. It just stepped over them.

πŸ” continue vs break

This is the part people mix up. So let’s make it clear. Both continue and break change how a loop runs. But they do very different things.

  • break leaves the loop completely. Nothing after the loop’s current item runs. The loop is over.
  • continue skips only the current turn. The loop keeps going with the next item.

Here they are side by side. First with break:

for number in range(1, 6):
if number == 3:
break
print(number)

Output

1
2

The loop stops the moment it sees 3. We never get 4 or 5.

Now the same loop with continue:

for number in range(1, 6):
if number == 3:
continue
print(number)

Output

1
2
4
5

This time only 3 is missing. The loop skipped it and carried on to the end.

Here is the difference in one table:

Statement What it does Does the loop continue?
break Leaves the loop right away No, the loop ends
continue Skips the rest of this turn Yes, with the next item

⚠️ Common Mistakes

A couple of things confuse people with continue. Watch out for these.

Putting continue where there is no item left to skip can cause an endless loop in a while. If you skip before updating your counter, the counter never changes. Then the loop runs forever.

# ❌ Avoid: count never changes when we skip, so this never ends
count = 0
while count < 5:
if count == 2:
continue # jumps back up with count still 2, forever
print(count)
count += 1

In a while loop, update your counter before the continue. That way a skip still moves you forward.

# βœ… Good: count goes up first, so the skip is safe
count = 0
while count < 5:
count += 1
if count == 3:
continue
print(count)

Another mix-up is reaching for continue when a plain if would be clearer. If you only have one thing to do, just wrap it in an if. Save continue for when you want to skip several lines or several conditions cleanly.

# ❌ Avoid: continue here is more confusing than a simple if
for n in range(1, 4):
if n == 2:
continue
print(n)
# βœ… Good: a plain if reads better for a single action
for n in range(1, 4):
if n != 2:
print(n)

βœ… Best Practices

  • Use continue to skip the cases you do not care about early. That keeps the main work in your loop flat and easy to read.
  • In a while loop, always make sure your counter changes before any continue. Otherwise you will loop forever.
  • Keep the continue condition simple. If the if test gets long, pull it into a clearly named variable.
  • Reach for continue when there are several lines to skip. For a single action, a plain if is often clearer.

🧩 What You’ve Learned

βœ… continue skips the rest of the current loop turn and jumps to the next one.

βœ… Unlike break, continue does not leave the loop. It keeps it running.

βœ… It is great for skipping items you do not care about, like even numbers or blank entries.

βœ… In a while loop, update your counter before continue so you never get stuck in an endless loop.

Check Your Knowledge

Test what you learned. Pick an answer for each question, then click Check.

  1. 1

    What does the continue statement do?

    Why: continue skips the remaining lines in the current turn and jumps to the next item, staying inside the loop.

  2. 2

    What is the main difference between break and continue?

    Why: break exits the loop entirely, while continue skips the current turn and keeps the loop running.

  3. 3

    What does this print? for n in range(1, 6): if n == 3: continue print(n)

    Why: Only 3 is skipped by continue; the loop keeps going, so it prints 1, 2, 4, and 5.

  4. 4

    Why can continue cause an endless loop in a while loop?

    Why: If continue jumps over the counter update, the counter never changes and the while condition stays true forever.

πŸš€ What’s Next?

You now know how to skip a turn and how to leave a loop. Next up is a keyword that does nothing on purpose. It is more useful than it sounds.

pass Statement

Share & Connect