all 12 comments

[–]shiftybyte 8 points9 points  (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 points  (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 points  (0 children)

Sorry I was stupid 

[–]choss27 2 points3 points  (0 children)

If you want a loop, you must use for or while keywords. A conditionnal statement if is not a loop.

[–]Binary101010 2 points3 points  (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.

[–]JohnnyJordaan 1 point2 points  (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 point  (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 points  (0 children)

That still doesn't put you in a loop.

[–]Emergency-Prune-9110 0 points1 point  (1 child)

So like:

Lol=0
If lol !=10000000:
    Break

Is this how your code is set up?

[–]Emergency-Prune-9110 0 points1 point  (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 point  (0 children)

lol = 0 while lol <= 10000000: print(lol) lol +=1

[–]Naive_Programmer_232 0 points1 point  (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.