0

i dont understand why my code doesnt stop at 5

i = 0 while True: i = i +1 if i==2: print("continue") continue if i==5: break print(i)

26th Apr 2020, 9:26 PM
sofronis
sofronis - avatar
5 Réponses
+ 2
i = 0 while True: i = i +1 if i==2: print("continue") continue if i==5: break print(i)
26th Apr 2020, 10:22 PM
sofronis
sofronis - avatar
+ 1
Because your block starting in line 7 is part of the block starting at line 4. So if i==2, you don't get to the inner block, because there's the continue first, and if i!=2, you don't even enter this block to begin with. Maybe you get the wanted result if you pull out the inner block one indentation level.
26th Apr 2020, 9:30 PM
HonFu
HonFu - avatar
+ 1
The indentation is wrong. "if i==5:" is part of "if i==2:"
26th Apr 2020, 9:31 PM
Manu_1-9-8-5
Manu_1-9-8-5 - avatar
+ 1
Thank you so much
26th Apr 2020, 10:19 PM
sofronis
sofronis - avatar