8.3. Using a For Loop to Loop Through an ArrayΒΆ

You can also use a for loop to loop through all the elements of an array. Just start the index at 0 and loop while the index is less than the length of the array.

Mixed up programs

        7-3-1: The following method has the correct code to subtract amt from all the values in the array values (a field of the current object), but the code is mixed up.  Drag the blocks from the left into the correct order on the right and indent them correctly. You will be told if any of the blocks are in the wrong order or not indented correctly.public void subAll(int amt)
{
---
   for (int i = 0;
        i < values.length;
        i++)
   {
---
      values[i] = values[i] - amt;
---
   } // end for loop
---
} // end method
        
Next Section - 8.4. Looping From Back to Front