- 1
How many times will the following loop execute?
namespace SoloLearn { class Program { static void Main(string[] args) { int x = 1; while (x++ < 5) { if (x % 2 == 0) x += 2; } } } }
6 Réponses
+ 13
after 1st loop ) x will be 4
after 2nd loop) x will be 5
6 as final value of x [5++ is not < 5 so loop stops & x become 6]
+ 1
Twice x will be 2 and 5 at the if statement and 6 after exiting the loop.
+ 1
Just add code to show you how many times it loops if you're having a hard time understanding.
https://code.sololearn.com/c1yx4mJ7eQ47/?ref=app
+ 1
loop will run twice
+ 1
the loop will run twice
#so answer will be 2
0
The correct answer is 2