Python Break statement | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Python Break statement

How to take back a break statement back i to the loop, each time i try print, it says something like: File "source_file.py", line 1 break ^ SyntaxError: 'break' is outside of loop

9th May 2019, 8:48 PM
David Holmes Ng'andu
David Holmes Ng'andu - avatar
3 Answers
+ 3
Instead of using break try continue, this acts like break but moves on to the next loop while break exits the block, also spacing counts so break should be at the same indentation. If you post the code throwing the exception I could help more
9th May 2019, 9:06 PM
Brian Petry
Brian Petry - avatar
+ 3
The error message says that you're using a break statement in line 1. That's impossible since a break statement must be in a loop: while True: # start loop print() # do something break # break loop
10th May 2019, 5:15 AM
Anna
Anna - avatar
+ 1
Use continue if you want to go back to the loop and break if you wanna finish the loop
10th May 2019, 3:47 AM
Mauricio Rodriguez
Mauricio Rodriguez - avatar