Can anyone explain how the answer is 4? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can anyone explain how the answer is 4?

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

24th May 2019, 6:04 AM
Nitin Bhattacharyya
Nitin Bhattacharyya - avatar
3 Answers
+ 4
The while loop is executed only once, because val never becomes bigger than 25. So val start from 1 and it is auto-incremented three times: result is 4!
24th May 2019, 6:08 AM
Bilbo Baggins
Bilbo Baggins - avatar
+ 4
Initially, val is 1. Then the do loop is executed and val is incremented two times (val=3). Then the while condition is checked for the first time. It contains another increment, so val is 4 now. 4 > 25 is false and the loop is not executed again
24th May 2019, 6:09 AM
Anna
Anna - avatar
+ 1
Thanks a lot,I get it now
24th May 2019, 6:11 AM
Nitin Bhattacharyya
Nitin Bhattacharyya - avatar