python - Break And Continue Statement in nested loops - Stack Overflow
[deleted by user]
Why would or should I use "break" and "continue" in my loops?
[deleted by user]
Videos
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?