Iterating
Iteration is the act of repeating an action. With arrays, you'll usually be iterating to print some or all elements, or searching for a particular value or values. There are several different loops that can be used to accomplish this task. For the purposes of these examples, we will use the following array:
for Loop
while Loop
forEach method
File Location
We will be working in the following file:
Practice
Create a new array with 5 elements. Use each of the above to print each element to the console.
Create a new blank array. Use one of the types of loops to iterate over the first array and push each value into the second array.
Try to iterate over the first array with a
do/while
loop. Print each element to the console.
Last updated