+ 1
Hi everyone, why is it getting 25 as an output in this code? Isn't it "a < 25" after all?
3 Respostas
+ 4
Well, at some point in time it reaches a = 20.
The next command asks if a < 25. It is true, so then it makes a+=5, now a is not < 25, so a remains = 25 and the loop stops.
+ 3
int a = 5;
while (a < 25) {
a = a + 5;
Here .. when a= 5, it will print 5+5 = 10.. similarly when a=10 , it will print 15.. and it goes on . So when a= 20 , it will print 25.. and when a= 25 . It will stop.
+ 1
Oh thanks a lot !!