New course! Every coder should learn Generative AI!
Try a free lesson0
Can anyone explain how the answer is 4?
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!
+ 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
+ 1
Thanks a lot,I get it now