Have you ever been writing a loop in Python and thought, “I just want to skip this one thing and move on to the next item”? Maybe you’re processing a list of users but want to skip over administrators, or you’re analyzing numbers and need to ignore zeros. Manually handling these skips with complex if statements can get messy.

What if Python gave you a simple, powerful command to do exactly that? Good news: it does! In this guide, you’ll master the Python continue statement. By the end, you’ll know exactly how to use continue to make your loops smarter, cleaner, and more efficient. Let’s dive in!
What is the Python Continue Statement?
In simple terms, the continue statement is like a “skip” button for your loops. When Python encounters continue inside a for or while loop, it immediately stops the current iteration and jumps back to the top of the loop to start the next one.
Think of it like reading a book chapter-by-chapter. If you start a chapter and realize it’s a filler you’re not interested in, you don’t close the entire book (that would be the break statement). Instead, you just skip to the next chapter. That’s what continue does—it skips the rest of the code for the current item and moves on to the next one.
The key takeaway is: continue does not exit the loop; it only terminates the current iteration.
How Continue Works in a For Loop
Let’s see the continue statement in action with a for loop. We’ll start with the example from the video: printing all odd numbers from 1 to 100.
# Printing odd numbers from 1 to 100 using 'continue'
for number in range(1, 101):
if number % 2 == 0: # Check if the number is even
continue # If it is even, skip the rest of the loop
print(number) # This line only runs for odd numbersCode Explanation:
- The loop runs through numbers 1 to 100.
- For each number, it checks
if number % 2 == 0. This condition isTrueif the number is even (divisible by 2). - If the condition is
True, thecontinuestatement executes. This immediately sends the program flow back to the top of the loop (for number in range...) for the next number. Theprint(number)statement is skipped. - If the condition is
False(meaning the number is odd), thecontinueis ignored, and the program proceeds toprint(number).
When you run this code, you’ll see an output of all odd numbers: 1, 3, 5, 7, …, 99.
Another Practical Example: Skipping Specific Data
Let’s imagine you have a list of temperatures and you want to process only those that are valid (e.g., above -50°C). The continue statement is perfect for this.
# Processing a list of temperatures, skipping invalid ones
temperatures = [22.5, -100, 18.0, -273, 25.5, 30.0]
for temp in temperatures:
if temp < -50: # Check for invalid temperature
print(f"Skipping invalid reading: {temp}°C")
continue
# This block only processes valid temperatures
fahrenheit = (temp * 9/5) + 32
print(f"{temp}°C is {fahrenheit:.1f}°F")Output:
22.5°C is 72.5°F Skipping invalid reading: -100°C 18.0°C is 64.4°F Skipping invalid reading: -273°C 25.5°C is 77.9°F 30.0°C is 86.0°F
How Continue Works in a While Loop
The continue statement works the same way in while loops, but there’s a critical detail to remember to avoid an infinite loop. Let’s adapt our first example to use a while loop, printing multiples of 5.
# Printing multiples of 5 from 5 to 100 using a while loop and 'continue'
number = 1
while number <= 100:
if number % 5 != 0: # If the number is NOT a multiple of 5
number += 1 # Increment the counter FIRST
continue # Then skip to the next iteration
print(number) # This only runs for multiples of 5
number += 1 # Don't forget to increment here too!Code Explanation & Crucial Warning:
- We start with
number = 1. - The loop runs as long as
number <= 100. - If the number is not a multiple of 5 (
number % 5 != 0), we do two things:- First, we increment the counter (
number += 1). This is the critical step! - Then, we call
continueto skip theprintstatement.
- First, we increment the counter (
- If the number is a multiple of 5, we print it and then increment the counter.
Why do we increment before continue? If we didn’t, the loop would get stuck. For example, if number is 1, the condition is True, and continue runs. It would jump back to the top of the loop, but number would still be 1. The condition would be True again, leading to an infinite loop. Always ensure your loop variable progresses before using continue in a while loop!
Continue vs. Break: What’s the Difference?
This is a common point of confusion for beginners. Let’s clear it up:
continue: Skips the rest of the current iteration and moves to the next one. The loop itself continues running.break: Immediately terminates the entire loop altogether. No more iterations happen.
Here’s a quick comparison:
# Demonstrating 'break' vs 'continue'
print("Using BREAK:")
for i in range(1, 6):
if i == 3:
break
print(i)
# Output: 1, 2
print("\nUsing CONTINUE:")
for i in range(1, 6):
if i == 3:
continue
print(i)
# Output: 1, 2, 4, 5Ready to Go from Basics to Pro?
You’ve just added a powerful tool to your Python toolkit! Understanding control flow with continue and break is a fundamental step, but there’s a whole world of Python mastery to explore. If you enjoyed this clear, step-by-step breakdown, imagine learning everything from data structures to web development with the same structured, beginner-friendly approach.
Our comprehensive course is designed to take you from basics to pro with expert guidance, hands-on projects, and a supportive community. If you’re serious about mastering Python, check out our pre-recorded python comprehensive video course.
Conclusion
The Python continue statement is your go-to command for fine-tuning loop behavior. It allows you to elegantly skip over items that don’t meet certain criteria, making your code more readable and efficient. Remember, it’s all about skipping the current iteration, not stopping the whole loop. The key difference from break is that continue keeps the loop going, while break stops it entirely. Keep practicing by writing your own loops that skip even numbers, specific letters, or invalid data entries. The more you code, the more intuitive it will become!
Common Questions About the Continue Statement
Can I use multiple continue statements in a single loop?
Yes, you can have multiple continue statements under different conditions. However, for readability, it’s often better to structure your conditions so that you only need one.
Does continue work with nested loops?
Yes, but it’s important to know that continue only affects the innermost loop it is placed in. It will skip the current iteration of that inner loop, not any outer loops.
When should I use continue versus a complex if condition?continue is best used when you want to skip an iteration early on, avoiding a large block of indented code inside an if/else statement. It can make your code flatter and easier to read. If the logic for skipping is simple, a plain if might be sufficient. Use your judgment for what makes the code clearest.















