197k views
3 votes
How many times will the following loop repeat?

i = 2; while i <= 16; i = i+2; end

A. 0 times

B. 2 times

C. 8 times

D. 16 times

1 Answer

5 votes

Answer:

8 times

Step-by-step explanation:

The while is execute again and again until the condition is TRUE.

In the question:

the value of i=2, when program enter the loop it check the condition when

2 <= 16, condition TRUE. it update the value i = 4.

Again the loop check condition, 4 <= 16, condition TRUE, i become 6 and so on...

4,6,8,10,12,14,16

when i = 16 loop condition is also TRUE. 16 <= 16. So, it again run the loop and i become 18.

then, the loop condition false and it exit the loop.

so, i run until 18

4,6,8,10,12,14,16,18

Therefore, the answer is 8 times.

User John Dorean
by
5.6k points