Multiple choice technology performance

You want to loop through a block of code 10 times using the for loop. What would accomplish this?

  1. For (i = 0; i < 10; i--)

  2. For (i = 1; i < 10; i--)

  3. For (i = 1; i < 10; i++)

  4. For (i = 1; i <= 10; i++)

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

A for loop that executes 10 times requires starting at 1, continuing while i is less than or equal to 10, and incrementing i each iteration. Option A and B use i-- which would decrement, causing infinite loops. Option C only runs 9 times (i from 1 to 9). Option D correctly runs from i=1 to i=10 inclusive.