+ 1

help needed please...🤔

Whenever i run this program it says something about the break statement not being in the loop or something. Can u pls tell me what im doing wrong? Thanks a lot. Edit: Code is while True: a=0 print (a) if (a==a): print (a+12) if a==144: break

2nd Jul 2017, 9:09 PM
scottwhitfield
scottwhitfield - avatar
6 Respostas
+ 7
Could you please show the code so we could help?
2nd Jul 2017, 9:13 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 5
Exactly, @Aisinthalor is right. You have to structure your loop - indent the code properly to make it a logical block. Only then the "break" will work.
2nd Jul 2017, 9:23 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 1
Oops sorry lol it's while True: a=0 print (a) if (a==a): print (a+12) if a==144: break @kuba
2nd Jul 2017, 9:16 PM
scottwhitfield
scottwhitfield - avatar
+ 1
first: your code will run forever, since a will be 0 for all time, and second: the break statement is not inside the loop (at least it looks like it here) you have to indent everything in your loop
2nd Jul 2017, 9:20 PM
Aisinthalor
Aisinthalor - avatar
+ 1
Ok thanks a lot
2nd Jul 2017, 9:23 PM
scottwhitfield
scottwhitfield - avatar
+ 1
so it's just: while True: a=0 print (a) print (a+12) (since a can't be something else than a 😉) if a==144: break a += 12 (or a = a +12 alternatively, to be sure that your loop terminates at the point you want it to)
2nd Jul 2017, 9:27 PM
Aisinthalor
Aisinthalor - avatar