0
How many times is the body of the following loop executed? What is the value of x after the loop termination?
int x = 15; do { x −= 2; if (x < 5) { break; } } while (true);
5 Answers
0
Rao Muzaffar
Yes. 5 times.
edited:
It works for 6 times.
+ 1
🅰🅹 🅐🅝🅐🅝🅣
Yes. It works for 6 times. But I typed '2nd' for two times .
0
Rao Muzaffar
x=15
1st round
x-=2//x=13
In if statement:
x<5= 13<5= false//so loop is not terminate.
2nd round
x-=2//x=11
In if statement:
x<5= 11<5= false//so loop is not terminate.
3rd round
x-=2//x=9
In if statement:
x<5= 9<5= false//so loop is not terminate.
4th round
x-=2//x=7
In if statement:
x<5= 7<5= false//so loop is not terminate.
5th round:
x-=2//x=5
In if statement:
x<5= 5<5= false//so loop is not terminate.
6th round:
x-=2//x=3
In if statement:
x<5= 3<5= true//so loop is terminated
0
So loop will execute 5 times??
0
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
Check again that is 6 times. On 6th time loop is breaking.
Rao Muzaffar
did you verify before giving best answer mark?