
The Python continue statement is a loop control tool that gives you precise control over which iterations of a loop actually execute their full body. When Python encounters a continue statement inside a loop, it immediately skips the rest of the loop body for that iteration and jumps directly to the next one. The loop itself does not stop — it keeps going until all iterations are complete, but certain iterations get cut short.
Understanding the Python continue statement helps you write cleaner loop logic, filter out unwanted values, and skip over conditions you do not want to process without having to break out of the loop entirely.
When a loop runs in Python, it normally executes every line of code in the loop body on every single iteration. But sometimes you only want to execute the full body under certain conditions, and skip the rest when those conditions are not met. That is exactly what the Python continue statement is designed for.
Instead of stopping the loop the way break does, continue just skips the remainder of the current iteration and moves on to the next one. The loop carries on running until all iterations are finished.
Here is the simplest example of the Python continue statement in action:
for number in range(1, 8):
if number == 4:
continue
print(number)
1
2
3
5
6
7
The loop runs from 1 to 7. When number equals 4, the continue statement fires and the print call is skipped for that one iteration. Every other number prints normally. Notice that 4 is simply absent from the output — the loop did not stop, it just jumped over that value and continued with 5.
The most frequent use of the Python continue statement is inside a for loop when you need to filter out specific values while still processing everything else in the sequence. This approach is much cleaner than wrapping your entire loop body in a large if block.
Imagine you have a list of product prices and some entries are marked as -1 to indicate a missing price. You want to print only the valid prices:
prices = [29.99, -1, 14.50, -1, 7.00, 45.00, -1, 22.75]
for price in prices:
if price == -1:
continue
print(f"Valid price: ${price}")
Valid price: $29.99
Valid price: $14.5
Valid price: $7.0
Valid price: $45.0
Valid price: $22.75
Each time the loop encounters a -1, the Python continue statement skips the print call and moves on to the next price. The loop processes the entire list without needing a nested if-else structure.
Another very common pattern is skipping empty strings from a dataset:
entries = ["Alice", "", "Bob", " ", "Charlie", "", "Diana"]
for entry in entries:
if not entry.strip():
continue
print(f"Processing: {entry}")
Processing: Alice
Processing: Bob
Processing: Charlie
Processing: Diana
The Python continue statement skips any entry that is empty or contains only whitespace. The strip method removes surrounding spaces, and the not keyword treats the resulting empty string as falsy, triggering the skip.
The Python continue statement works inside while loops just as naturally as it does in for loops. When continue fires inside a while loop, execution jumps back to the loop condition check rather than to the next item in a sequence.
Here is an example that counts from 1 to 10 but skips all even numbers:
number = 0
while number < 10:
number += 1
if number % 2 == 0:
continue
print(number)
1
3
5
7
9
One critical thing to notice here: the line that increments number comes before the continue check. This placement matters enormously in while loops. If the increment came after the continue, the variable would never get updated when continue fires, and you would end up in an infinite loop that never advances. Always make sure any update to the loop variable happens before the continue statement in a while loop.
A practical example is a command processor that keeps asking for valid input and skips invalid commands using continue:
valid_commands = ["start", "stop", "pause", "resume"]
while True:
user_input = input("Enter a command: ").strip().lower()
if user_input not in valid_commands:
print(f"Unknown command. Valid options: {valid_commands}")
continue
print(f"Executing: {user_input}")
if user_input == "stop":
break
Enter a command: go
Unknown command. Valid options: ['start', 'stop', 'pause', 'resume']
Enter a command: launch
Unknown command. Valid options: ['start', 'stop', 'pause', 'resume']
Enter a command: start
Executing: start
Enter a command: stop
Executing: stop
When the user types an unrecognized command, the Python continue statement skips the execution code and loops back to the input prompt. When a recognized command arrives, execution flows through normally. The break handles the stop command to exit the while loop entirely.
When you have one loop nested inside another, the Python continue statement only affects the innermost loop it is placed in. The outer loop runs completely uninterrupted.
for row in range(1, 4):
print(f"Row {row}:")
for col in range(1, 6):
if col == 3:
continue
print(f" Column {col}")
Row 1:
Column 1
Column 2
Column 4
Column 5
Row 2:
Column 1
Column 2
Column 4
Column 5
Row 3:
Column 1
Column 2
Column 4
Column 5
The continue fires only inside the inner for loop when col equals 3. Column 3 is skipped on every row, but the outer loop runs through all three rows without any impact. This behavior is consistent and predictable — continue is scoped to the loop it lives in.
If you need continue to affect the outer loop based on something that happens inside the inner loop, a flag variable is the standard solution:
for row in range(1, 5):
skip_row = False
for col in range(1, 4):
if row == 2 and col == 2:
skip_row = True
break
if skip_row:
continue
print(f"Processing row {row}")
Processing row 1
Processing row 3
Processing row 4
The flag is set inside the inner loop, and the outer loop reads that flag after the inner loop finishes. When the flag is True, the Python continue statement skips the rest of the outer loop body for that iteration, effectively skipping row 2 entirely.
The Python continue statement pairs especially well with string conditions when you are processing lists of text data and want to skip items that do not meet a particular pattern or format.
Here is an example that processes a list of filenames and skips anything that does not have a .py extension:
filenames = [
"main.py",
"config.json",
"utils.py",
"README.md",
"parser.py",
"requirements.txt",
"tests.py"
]
for filename in filenames:
if not filename.endswith(".py"):
continue
print(f"Python file: {filename}")
Python file: main.py
Python file: utils.py
Python file: parser.py
Python file: tests.py
The str.endswith() method returns True if the string ends with the given suffix. Combined with the Python continue statement, it creates a clean filter that only processes the files you care about.
You can chain multiple continue conditions to filter on several criteria at once:
data = ["42", "hello", "-7", "", "100", "abc", "0"]
total = 0
for item in data:
if not item.strip():
continue
if not item.lstrip("-").isdigit():
continue
value = int(item)
if value <= 0:
continue
total += value
print(f"Adding {value} to total")
print(f"Final total: {total}")
Adding 42 to total
Adding 100 to total
Final total: 142
Three separate continue conditions guard the accumulation logic. The first skips empty strings, the second skips non-numeric text, and the third skips zero and negative numbers. Each continue handles one responsibility cleanly, which makes the logic easy to follow and modify independently.
This example builds a student grade report processor. It reads through a list of student records, uses the Python continue statement to skip incomplete records and failing grades, and produces a clean summary showing only valid passing students:
students = [
{"name": "Alice", "grade": 88, "subject": "Math"},
{"name": "Bob", "grade": None, "subject": "Science"},
{"name": "Charlie", "grade": 72, "subject": "Math"},
{"name": "Diana", "grade": 45, "subject": "English"},
{"name": "Eve", "grade": 95, "subject": "Science"},
{"name": "Frank", "grade": None, "subject": "Math"},
{"name": "Grace", "grade": 61, "subject": "English"},
{"name": "Henry", "grade": 83, "subject": "Science"},
]
passing_threshold = 60
report = []
for student in students:
if student["grade"] is None:
print(f"Skipping {student['name']}: grade not recorded")
continue
if student["grade"] < passing_threshold:
print(f"Skipping {student['name']}: grade {student['grade']} below passing threshold")
continue
report.append(student)
print("\n--- Passing Students Report ---")
for entry in report:
print(f"{entry['name']} | {entry['subject']} | Grade: {entry['grade']}")
Skipping Bob: grade not recorded
Skipping Diana: grade 45 below passing threshold
Skipping Frank: grade not recorded
--- Passing Students Report ---
Alice | Math | Grade: 88
Charlie | Math | Grade: 72
Eve | Science | Grade: 95
Grace | English | Grade: 61
Henry | Science | Grade: 83
The Python continue statement handles two distinct skip conditions in sequence. First it checks if the grade is None and skips that record if so. Then it checks if the grade falls below the passing threshold and skips that one too. Any student that passes both checks gets added to the final report. Because continue skips rather than stops, the loop always processes every student in the list before the report is printed.