+ 1

Hi everyone, why is it getting 25 as an output in this code? Isn't it "a < 25" after all?

https://code.sololearn.com/c26xdEuJCpA4/?ref=app

30th Jul 2022, 10:41 AM
Zeynep Bilge Özkan
Zeynep Bilge Özkan - avatar
3 Antworten
+ 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.
30th Jul 2022, 10:47 AM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
+ 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.
1st Aug 2022, 9:02 AM
Shruti Bubna
Shruti Bubna - avatar
+ 1
Oh thanks a lot !!
30th Jul 2022, 10:50 AM
Zeynep Bilge Özkan
Zeynep Bilge Özkan - avatar