- 1

Q. on while loop

why is the answer 2. ?? please explain

12th Sep 2016, 6:10 PM
J Helen
J Helen - avatar
2 Answers
0
can anyone dicuss the part related to %
2nd Dec 2016, 9:32 PM
Market Line
Market Line - avatar
- 1
That is because. int x = 1; while (x++ < 5) // if x is less than 5, do the loop. Now add 1 to x. So the first time would be while 1 < 5 do this. Now add one to 1. // Second time. while 4 < 5 do this. Now add 1 to 4. if 5 % 2 == 0 do this. FALSE. // Third time won't execute because 5 is not less than 5. { if(x % 2 == 0) // if 2 % 2 == 0 do this. { x +=2; // Add 2 to 2. } }
12th Sep 2016, 8:07 PM
Andreas BeEm Kvist
Andreas BeEm Kvist - avatar