Question Detail

COM 101 COM 101 Past Questions Objective Question

Question

Consider the code inside this bracket: (For i = 0 to 7 step 2 Print "blast off" Next i). How many times will the code section above execute the print statement?
Options
A 2
B 5
C 4
Correct Answer
D 7
Correct Answer

Option C is the correct answer.

Detailed Explanation

The loop runs from i=0 to 7 with step 2. Values: i=0, 2, 4, 6. That's 4 iterations. When i reaches 8, it stops because 8 is not <= 7.

Hint

Count the number of values: 0, 2, 4, 6.

Question Info