How many times will the following loop execute? Explain. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

How many times will the following loop execute? Explain.

How many times will the following loop execute? int x = 1; while (x++ < 5) { if (x % 2 == 0) x += 2; }

26th Jan 2017, 4:14 PM
Christopher
2 Answers
+ 1
int x = 1, c=0; while (x++ < 5) { if (x % 2 == 0) x += 2; ++c; } cout<<c; it will execute c times.
26th Jan 2017, 4:17 PM
Rishabh Agrawal
Rishabh Agrawal - avatar
0
2 times
26th Jan 2017, 4:21 PM
Athul P Ramachandran
Athul P Ramachandran - avatar