+ 1

Why it prints 3 times instead of 4? I thought it will print 5, 4, 3, 2 so it's 4 times, right? Can someone explain it to me? Thanks

11th Aug 2016, 10:27 PM
Faizal Khilmi Muzakki
Faizal Khilmi Muzakki - avatar
4 Réponses
+ 1
Because the condition says i<=2 so 2 isn't a output.
11th Aug 2016, 11:03 PM
Francisco Alejandro Vargas Fajardo
Francisco Alejandro Vargas Fajardo - avatar
+ 1
2<=2, Isn't it right?
12th Aug 2016, 12:57 AM
Faizal Khilmi Muzakki
Faizal Khilmi Muzakki - avatar
+ 1
I forgot to say that the condition have the "break", so that evade the "print"
12th Aug 2016, 1:09 AM
Francisco Alejandro Vargas Fajardo
Francisco Alejandro Vargas Fajardo - avatar
0
Because we decrement i just before evaluating it, so inmediatly after reaching 2 we enter the if and break the loop
15th Aug 2016, 5:24 PM
Thagus
Thagus - avatar