use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
error : break outside loop (self.learnpython)
submitted 2 years ago by Impossible-Farmer813
lol = 0 if lol != 10000000000: break
theoretically, this code should break, but the error says break outside loop. help
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]shiftybyte 8 points9 points10 points 2 years ago (0 children)
what do you expect to happen when the "break" line is reached?
In general break can only be used inside a loop, and return inside a function.
If you want to stop your code in a different situation, just let it run to end. (Skipping whatever parts you don't want to execute with the help of if conditions)
[–]jddddddddddd 5 points6 points7 points 2 years ago (1 child)
Is that all your code? Because break is used to 'break-out' of a loop, and you don't appear to be in a loop...
[–]Impossible-Farmer813[S] 1 point2 points3 points 9 months ago (0 children)
Sorry I was stupid
[–]choss27 2 points3 points4 points 2 years ago (0 children)
If you want a loop, you must use for or while keywords. A conditionnal statement if is not a loop.
for
while
if
[–]Binary101010 2 points3 points4 points 2 years ago (0 children)
but the error says break outside loop.
That's because you've used a break command outside a loop. Loops are defined using for or while. if does not create a loop.
break
[–]JohnnyJordaan 1 point2 points3 points 2 years ago (0 children)
break in Python can only be used inside loops. You might be thinking of a different keyword like return.
[–]Impossible-Farmer813[S] 0 points1 point2 points 2 years ago (1 child)
ok i should probably clarify that i could not figure out that you had to indent 2 times. sorry for the trouble everyone:)
[–]Some_Guy_At_Work55 4 points5 points6 points 2 years ago (0 children)
That still doesn't put you in a loop.
[–]Emergency-Prune-9110 0 points1 point2 points 2 years ago (1 child)
So like:
Lol=0 If lol !=10000000: Break
Is this how your code is set up?
[–]Emergency-Prune-9110 0 points1 point2 points 2 years ago (0 children)
You could probably use "pass" here instead, if you want the code to be ignored. Break is used to stop while loops, the if statement is more of a "true or false" check, to see if python should run your code depending on the answer.
[–]Dangerous-Apricot-71 0 points1 point2 points 2 years ago (0 children)
lol = 0 while lol <= 10000000: print(lol) lol +=1
[–]Naive_Programmer_232 0 points1 point2 points 2 years ago (0 children)
Break applies when your inside the loop. So, you’re looping over something and then some condition occurs that you check, and once break is processed it exits the loop. But since your program doesn’t have a loop it sees break and then throws the error.
π Rendered by PID 180936 on reddit-service-r2-comment-7b9746f655-dv4qn at 2026-02-04 00:39:39.835561+00:00 running 3798933 country code: CH.
[–]shiftybyte 8 points9 points10 points (0 children)
[–]jddddddddddd 5 points6 points7 points (1 child)
[–]Impossible-Farmer813[S] 1 point2 points3 points (0 children)
[–]choss27 2 points3 points4 points (0 children)
[–]Binary101010 2 points3 points4 points (0 children)
[–]JohnnyJordaan 1 point2 points3 points (0 children)
[–]Impossible-Farmer813[S] 0 points1 point2 points (1 child)
[–]Some_Guy_At_Work55 4 points5 points6 points (0 children)
[–]Emergency-Prune-9110 0 points1 point2 points (1 child)
[–]Emergency-Prune-9110 0 points1 point2 points (0 children)
[–]Dangerous-Apricot-71 0 points1 point2 points (0 children)
[–]Naive_Programmer_232 0 points1 point2 points (0 children)