Python Continue Statement
Last Updated : 11 Mar, 2025
Python continue statement is a loop control statement that forces to execute the next iteration of the loop while skipping the rest of the code inside the loop for the current iteration only, i.e. when the continue statement is executed in the loop, the code inside the loop following the continue statement will be skipped for the current iteration and the next iteration of the loop will begin.
Example:
Python for i in range(1, 11): if i == 6: continue print(i, end=" ")
Explanation: When i == 6, the continue statement executes, skipping the print operation for 6.
Syntax
while True:
...
if x == 10:
continue
print(x)
Parameters : The continue statement does not take any parameters.
Returns: It does not return any value but alters the flow of the loop execution by skipping the current iteration.
Examples of continue statement
Example 1: Skipping specific characters in a string
Python for char in "GeeksforGeeks": if char == "e": continue print(char, end=" ")
Explanation: Whenever char == 'e', the continue statement executes, skipping the print function for that iteration.
Example 2. Using continue in nested loops
Python a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] for row in a: for num in row: if num == 3: continue print(num, end=" ")
Explanation: continue statement skips printing 3 and moves to the next iteration, so all numbers except 3 are printed in a single line.
Example 3. Using continue with a while loop
Python i = 0 while i < 10: if i == 5: i += 1 # ensure the loop variable is incremented to avoid infinite loop continue print(i) i += 1
Explanation: When i == 5, the continue statement skips printing and jumps to the next iteration.
When to Use the Continue Statement?
We should use the continue statement when we need to control the flow of loops efficiently by skipping specific iterations while still executing the rest of the loop. Here are some key scenarios:
- Skipping Specific Values: When certain values should be ignored while continuing with the remaining iterations.
- Filtering Data Dynamically: When applying conditional checks to exclude specific elements from processing.
- Optimizing Loop Performance: When unnecessary computations can be avoided to improve efficiency.
For more loop control statements, refer to:
Similar Reads
Conditional Statements in Python Conditional statements in Python are used to execute certain blocks of code based on specific conditions. These statements help control the flow of a program, making it behave differently in different situations.If Conditional Statement in PythonIf statement is the simplest form of a conditional sta
6 min read
Python break statement The break statement in Python is used to exit or "break" out of a loop (either a for or while loop) prematurely, before the loop has iterated through all its items or reached its condition. When the break statement is executed, the program immediately exits the loop, and the control moves to the nex
5 min read
Nested-if statement in Python For more complex decision trees, Python allows for nested if statements where one if statement is placed inside another. This article will explore the concept of nested if statements in Python, providing clarity on how to use them effectively.Python Nested if StatementA nested if statement in Python
2 min read
Python Match Case Statement Introduced in Python 3.10, the match case statement offers a powerful mechanism for pattern matching in Python. It allows us to perform more expressive and readable conditional checks. Unlike traditional if-elif-else chains, which can become unwieldy with complex conditions, the match-case statement
7 min read
Statement, Indentation and Comment in Python Here, we will discuss Statements in Python, Indentation in Python, and Comments in Python. We will also discuss different rules and examples for Python Statement, Python Indentation, Python Comment, and the Difference Between 'Docstrings' and 'Multi-line Comments. What is Statement in Python A Pytho
7 min read