🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › python › break-continue-and-pass-in-python
Loop Control Statements - Python
July 12, 2025 - ... # Using For Loop for i in range(5): ... += 1 ... 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, ...
Discussions

python - Break And Continue Statement in nested loops - Stack Overflow
So i was experimenting the for-loop in Python and i decided let me use continue and break statements for experimentation and i got to know what's the difference. So "break" exits your loop More on stackoverflow.com
🌐 stackoverflow.com
[deleted by user]
The difference is that break entirely exits you from processing any more items that you’re looping over, while continue exits you from only your current item. An example is looping over a list of numbers from 1-10. Imagine you only want to do something to even numbers and odd numbers can be discarded. If you used break when you encountered an odd number, the rest of the numbers won’t get processed. More on reddit.com
🌐 r/learnpython
24
0
October 23, 2023
Why would or should I use "break" and "continue" in my loops?
There are times that break and/or continue are necessary, however most of the examples I see them used on this subreddit are the result of unclear logic. What I mean by 'unclear' is that the person writing the code takes 2-3 additional steps to achieve something that could be done in less. Usually what happens is people have the logic in their conditionals statements backwards. They check against a condition they don't actually care about, and break/continue past it, but then use the else block to do the logic they really want. Here's an example using your code, notice I flipped the >=9000 and changed the inner return to a break like CA suggested you do: def over_nine_thousand2(lst): sum1 = 0 for i in lst: sum1 += i if sum1 < 9000: continue else: break return sum1 IMO you should never go out of your way to use them if the code can be written to achieve the same logic without them. When I read your code, I immediately saw two return statements. While this is technically 'repeated' code, it actually does something useful. It conveys to me that there are two separate exit conditions for your function. One that returns as soon as it surpasses 9000, and one that returns if we never surpass 9000. Replacing the return sum1 inside the if statement with a break hides that fact, at least initially. Sure I'd figure that out going through the entire function, but break doesn't immediately convey an exit condition. tl;dr: improper use of break/continue often hides the intent of the code. More on reddit.com
🌐 r/learnpython
8
1
January 21, 2021
[deleted by user]
You'll run into different people with strong and competing opinions about a lot of things in this field. I don't use break or continue very often, but there are definitely circumstances where they can make code more clear. You're just going to have to learn the specific rules that this professor wants you to follow, and follow them. More on reddit.com
🌐 r/learnprogramming
226
561
September 9, 2022
🌐
Accuweb
accuweb.cloud › home › python break, continue, pass statements with examples
Python Break, Continue, Pass Statements with Examples
December 11, 2023 - For example, when processing a dataset, you might skip missing or incorrect values using continue. The pass statement is different from break and continue because it does nothing at all. It acts as a placeholder statement where Python requires code syntactically but you do not want to execute anything yet.
🌐
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 print ('Current variable value :', var) print ("Good bye!")
🌐
Problem Solving with Python
problemsolvingwithpython.com › 09-Loops › 09.03-Break-and-Continue
Break and Continue - Problem Solving with Python
Remember the keyword break cause the program to exit a loop. continue is similar, but continue causes the program to stop the current iteration of the loop and start the next iteration at the top of the loop. A code section that uses continue in a for loop is below.
🌐
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 - Check out DigitalOcean App Platform and deploy a Python project directly from GitHub in minutes. ... The break statement in Python allows you to exit a loop immediately when a specific condition is met, which is especially useful for terminating early during search or validation operations.
🌐
W3Schools
w3schools.in › python › break-and-continue
Break and Continue in Python - W3Schools
For example, have a look at the ... will terminate when the variable count becomes equal to 3. The continue statement causes the loop to skip its current execution at some point and move on to the next iteration....
🌐
Unstop
unstop.com › home › blog › python break and continue statements explained with examples
Break And Continue Statement In Python
October 18, 2024 - The break statement terminates the nearest enclosing loop, while continue skips the current iteration and proceeds to the next one. Both are used to control loop execution based on specific conditions.
Find elsewhere
🌐
Educative
educative.io › answers › what-are-break-continue-and-pass-statements-in-python
What are break, continue, and pass statements in Python?
Let’s see the flowchart below for a pictorial representation of how the use of break just lets us exit the loop whenever we want: The break statement allows one to exit a loop early · The continue statement allows us to skip the rest of the ...
🌐
CodeHS
codehs.com › tutorial › 13498
Tutorial: Break and Continue in Python | CodeHS
Learn how to use the break and continue statements in your Python programs.
🌐
Tutor Python
tutorpython.com › python-break-continue-statement
Python Break & Continue Statement - Tutor Python
October 19, 2023 - Example of Python break statement in a while loop- i = 0 while i < 10: print(i) if i == 5: break i += 1 # output: 0 1 2 3 4 5 · Here, the loop starts with the variable i being 0 and will continue to execute as long as i is less than 10.
🌐
OpenStax
openstax.org › books › introduction-python-programming › pages › 5-4-break-and-continue
5.4 Break and continue - Introduction to Python Programming | OpenStax
March 13, 2024 - A break condition is triggered ... >= 5: print(i) break i += 1 ... A continue statement allows for skipping the execution of the remainder of the loop without exiting the loop entirely....
🌐
W3Schools
w3schools.com › python › ref_keyword_continue.asp
Python continue Keyword
Python Bootcamp Python Certificate Python Training ... The continue keyword is used to end the current iteration in a for loop (or a while loop), and continues to the next iteration. ... Use the break keyword to end the loop comple...
🌐
Built In
builtin.com › software-engineering-perspectives › pass-vs-continue-python
Pass vs. Continue in Python Explained | Built In
Continue: The continue statement in Python is used to skip the remaining code inside a loop for the current iteration only · Break: A break statement in Python alters the flow of a loop by terminating it once a specified condition is met.
🌐
Reddit
reddit.com › r/learnpython › [deleted by user]
difference between break and continue in python
October 23, 2023 - Subreddit for posting questions and asking for general advice about all topics related to learning python. ... The difference is that break entirely exits you from processing any more items that you’re looping over, while continue exits you from only your current item.
🌐
Reddit
reddit.com › r/learnpython › why would or should i use "break" and "continue" in my loops?
r/learnpython on Reddit: Why would or should I use "break" and "continue" in my loops?
January 21, 2021 -

I've been learning Python off CodeAcademy and noticed that for the section on for loops I can achieve the intended outcome of my loop without the use of "continue" and "break". Instead I can just use an empty "if" in place of a continue and a correctly placed "return" statement instead of a break.

I've been taught in Java up till this point hence why I am probably thinking like this in regards to the "Break" and "Continue" syntax in Python.

Here is my code from the example provided of what I mean: The goal, is for me to sum up the items in a list until they reach over 9k and return the total as soon as sum1 reaches over 9k. If they don't total over 9k by the end of the list I need to return the total values of all list elements added together. CodeAcademy clearly wanted me to use a break in my if statement, yet I can achieve the same output if I return sum1?

Top answer
1 of 3
1
There are times that break and/or continue are necessary, however most of the examples I see them used on this subreddit are the result of unclear logic. What I mean by 'unclear' is that the person writing the code takes 2-3 additional steps to achieve something that could be done in less. Usually what happens is people have the logic in their conditionals statements backwards. They check against a condition they don't actually care about, and break/continue past it, but then use the else block to do the logic they really want. Here's an example using your code, notice I flipped the >=9000 and changed the inner return to a break like CA suggested you do: def over_nine_thousand2(lst): sum1 = 0 for i in lst: sum1 += i if sum1 < 9000: continue else: break return sum1 IMO you should never go out of your way to use them if the code can be written to achieve the same logic without them. When I read your code, I immediately saw two return statements. While this is technically 'repeated' code, it actually does something useful. It conveys to me that there are two separate exit conditions for your function. One that returns as soon as it surpasses 9000, and one that returns if we never surpass 9000. Replacing the return sum1 inside the if statement with a break hides that fact, at least initially. Sure I'd figure that out going through the entire function, but break doesn't immediately convey an exit condition. tl;dr: improper use of break/continue often hides the intent of the code.
2 of 3
1
What if you were doing something more complex to sum1 before returning it? You would have to duplicate all of that code. Continue is used to skip to the next loop iteration so return doesn't replace that in any way unless you wrap the entire loop contents in another function that you return. I've been taught in Java up till this point hence why I am probably thinking like this in regards to the "Break" and "Continue" syntax in Python. Break and continue are pretty standard in most programming languages, including Java.
🌐
freeCodeCamp
freecodecamp.org › news › python-break-and-python-continue-how-to-skip-to-the-next-function
Python Break and Python Continue – How to Skip to the Next Function
March 14, 2022 - We could add a condition inside ... + 1 if num == 9: break ... You can use the continue statement if you need to skip the current iteration of a for or while loop and move onto the next iteration....
🌐
Learn Python
learnpython.dev › 02-introduction-to-python › 110-control-statements-looping › 40-break-continue
break, continue, and return :: Learn Python by Nina Zakharenko
break and continue allow you to control the flow of your loops. They’re a concept that beginners to Python tend to misunderstand, so pay careful attention. The break statement will completely break out of the current loop, meaning it won’t run any more of the statements contained inside of it.