my version is 3.5.2 and several attempts to make a break statement has failed. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

my version is 3.5.2 and several attempts to make a break statement has failed.

does break have to be in parenthisis, quotation? mine is still runining at the time of this printing. i = 5 while "TRUE": print(i) i = i + 1 if i <= 2: break

7th Nov 2016, 4:31 AM
Douglas Frey
Douglas Frey - avatar
5 Answers
+ 2
because you init i with 5 which is greater than 2, so you never will fulfill your if condition. also you have to intent all lines which should be within the loop. from intent perspective only the print statement is within the loop
7th Nov 2016, 4:40 AM
Gunther Strauss
Gunther Strauss - avatar
0
mine will not run unless indentation and syntax are correct. i = 5 while True: print(i) i = i + 1 if i <= 2: break still running.
7th Nov 2016, 5:02 AM
Douglas Frey
Douglas Frey - avatar
0
Same Problem try i = 20 you never fulfill the condition i <= 2 because you start with 5!
7th Nov 2016, 6:22 AM
Gunther Strauss
Gunther Strauss - avatar
0
that is the question i was given, it started as i = 5.
7th Nov 2016, 10:56 AM
Douglas Frey
Douglas Frey - avatar
0
why don't you use a statement i mean you can use print('Stop') in the if condition and stop the probleme of this break. and about your code it will runs because i>2 and i starts from 5 and will add 1 in each line i think you want to use i = i - 1 to get what you want hope that helps
8th Nov 2016, 7:34 AM
Otmane Guourch
Otmane Guourch - avatar