Here's a simple example:
for letter in 'Django':
if letter == 'D':
continue
print("Current Letter: " + letter)
Output will be:
Current Letter: j
Current Letter: a
Current Letter: n
Current Letter: g
Current Letter: o
It skips the rest of the current iteration (here: print) and continues to the next iteration of the loop.
Top answer 1 of 10
237
Here's a simple example:
for letter in 'Django':
if letter == 'D':
continue
print("Current Letter: " + letter)
Output will be:
Current Letter: j
Current Letter: a
Current Letter: n
Current Letter: g
Current Letter: o
It skips the rest of the current iteration (here: print) and continues to the next iteration of the loop.
2 of 10
112
I like to use continue in loops where there are a lot of contitions to be fulfilled before you get "down to business". So instead of code like this:
for x, y in zip(a, b):
if x > y:
z = calculate_z(x, y)
if y - z < x:
y = min(y, z)
if x ** 2 - y ** 2 > 0:
lots()
of()
code()
here()
I get code like this:
for x, y in zip(a, b):
if x <= y:
continue
z = calculate_z(x, y)
if y - z >= x:
continue
y = min(y, z)
if x ** 2 - y ** 2 <= 0:
continue
lots()
of()
code()
here()
By doing it this way I avoid very deeply nested code. Also, it is easy to optimize the loop by eliminating the most frequently occurring cases first, so that I only have to deal with the infrequent but important cases (e.g. divisor is 0) when there is no other showstopper.
GeeksforGeeks
geeksforgeeks.org › python › python-continue-statement
Python Continue Statement - GeeksforGeeks
Example 3. Using continue with a while loop
Published 1 week ago
Videos
17:25
Python Break, Continue & Pass – Loops Made Simple - YouTube
04:44
Break Continue in Python | 26 - YouTube
04:33
Understanding the continue Statement in Loops - YouTube
09:04
Break & Continue with Loops | Python Programming Ep. 18 - YouTube
03:10
break and continue in Python loops (CS105 at UIUC) - YouTube
05:58
The continue Statement with for loop | How to use The continue ...
Programiz
programiz.com › python-programming › break-continue
Python break and continue (With Examples)
We can also terminate the while loop using the break statement. For example, i = 0 while i < 5: if i == 3: break print(i) i += 1 ... The continue statement skips the current iteration of the loop and the control flow of the program goes to the next iteration.
Real Python
realpython.com › python-continue
Skip Ahead in Loops With Python's continue Keyword – Real Python
March 27, 2025 - In a while loop, continue transfers control back to the condition at the top of the loop. If that condition is True, then the loop body will run again. If it’s False, then the loop ends. Consider the following while loop. It leverages Python’s walrus operator to get user input, casts it to an int, and adds the number to a running total.
Tutorialspoint
tutorialspoint.com › python › python_continue_statement.htm
Python - Continue Statement
Python continue statement is used to skip the execution of the program block and returns the control to the beginning of the current loop to start the next iteration. When encountered, the loop starts next iteration without executing the remaining
W3Schools
w3schools.com › python › ref_keyword_continue.asp
Python continue Keyword
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... The continue keyword is used to end the current iteration in a for loop (or a while loop), ...
W3Schools
w3schools.com › python › gloss_python_for_continue.asp
Python Continue For Loop
fruits = ["apple", "banana", "cherry"] for x in fruits: if x == "banana": continue print(x) Try it Yourself » · Python For Loops Tutorial For Loop Through a String For Break Looping Through a Range For Else Nested Loops For pass
W3Schools
w3schools.com › python › python_for_loops.asp
Python For Loops
Exit the loop when x is "banana", but this time the break comes before the print: fruits = ["apple", "banana", "cherry"] for x in fruits: if x == "banana": break print(x) Try it Yourself » · With the continue statement we can stop the current iteration of the loop, and continue with the next:
Tutorialspoint
tutorialspoint.com › python › python_loop_control.htm
Python Break, Continue and Pass Statements
The continue statement can be used in both while and for loops. for letter in 'Python': # First Example if letter == 'h': continue print ('Current Letter :', letter) var = 10 # Second Example while var > 0: var = var -1 if var == 5: continue ...
CodeSignal
codesignal.com › learn › courses › exploring-iterations-and-loops-in-python › lessons › mastering-loop-controls-break-and-continue-in-python
Mastering Loop Controls: Else, Break and Continue in Python
In this example, the continue statement skips the rest of the loop body for items that are already packed, allowing the loop to only print out the items that still need to be packed. This way, we efficiently focus on what is left to be packed without unnecessary checks or reminders for already ...
Python documentation
docs.python.org › 3 › tutorial › controlflow.html
4. More Control Flow Tools — Python 3.14.3 documentation
For example (no pun intended): >>> # Measure some strings: >>> words = ['cat', 'window', 'defenestrate'] >>> for w in words: ... print(w, len(w)) ... cat 3 window 6 defenestrate 12 · Code that modifies a collection while iterating over that same collection can be tricky to get right. Instead, it is usually more straight-forward to loop over a copy of the collection or to create a new collection:
Accuweb
accuweb.cloud › home › python break, continue, pass statements with examples
Python Break, Continue, Pass Statements with Examples
December 11, 2023 - Once the break statement runs, Python exits the loop and continues executing the code that appears after the loop. This is useful when you want to stop searching or processing once a condition has been satisfied. ... count = 0 while count < 5: print("Iteration:", count) if count == 2: break count += 1 Output Iteration: 0 Iteration: 1 Iteration: 2Copy · In this example, the loop normally would run five times.
Python Tutorial
pythontutorial.net › home › python basics › python continue
Using Python continue Statement to Control the Loops
March 26, 2025 - How it works. First, iterate over a range of numbers from 0 to 9 using a for loop with the range() function. Second, if the index is an odd number, skip the current iteration and start a new one. Note that the index % 2 returns 1 if the index is an odd number and 0 if the index is an even number.
DigitalOcean
digitalocean.com › community › tutorials › how-to-use-break-continue-and-pass-statements-when-working-with-loops-in-python-3
How to Break Out of Multiple Loops in Python | DigitalOcean
August 7, 2025 - Understanding and utilizing these ... a comprehensive guide to using Python’s break, continue, and pass statements within loops to control flow effectively. It explains the purpose and behavior of each statement with practical code examples and output demonstration...
LearnDataSci
learndatasci.com › solutions › python-continue
Python Continue - Controlling for and while Loops – LearnDataSci
As mentioned previously, continue is used to skip to the end of the current iteration of a loop. Therefore, Python will only bypass code in situations that trigger continue. For a more complex example, let's say we'd like to iterate through a list of numbers and find the square root of each number in the list.