0

Please somebody explain some simple code

I have while loop with break after it gets 4, but in output I have 2 times 4 instead of 1, why ? https://code.sololearn.com/cTgGRr44AmIO/?ref=app

4th Nov 2017, 8:35 PM
Ksu Krasnytskaya
Ksu Krasnytskaya - avatar
3 Réponses
0
while you are in the x==3 loop you increase it to 4 and output it (line 11: first "4"), then it loops again and outputs it again (line 6: second "4") then you are stopping the loop
4th Nov 2017, 8:39 PM
Jeremy
Jeremy - avatar
+ 1
thank you very much: )
4th Nov 2017, 8:41 PM
Ksu Krasnytskaya
Ksu Krasnytskaya - avatar
0
because you increment x before printing it will print 3 then 4 in the same loop then at the start of the next loop print 4 then break from loop.
4th Nov 2017, 8:39 PM
Enzo
Enzo - avatar