Question Detail

COM 101 COM 101 Past Questions Objective Question

Question

42. How many iterations are performed in the code snippet below sum = 0, i = 10 Do sum = sum + i i = i - 2 While (i >= 4)
Options
A 5
B 3
C 4
Correct Answer
D Infinity
Correct Answer

Option C is the correct answer.

Detailed Explanation

Loop runs while i >= 4. i starts at 10, then 8, 6, 4. When i becomes 2, loop stops. That's 4 iterations (i=10,8,6,4).

Hint

Count how many times i is >= 4 as it decreases by 2.

Question Info