Zoo Loop Ex: Use for loops to rewrite the file.
// Array of zoo animals.
var zooAnimals = ["Zebra", "Rhino", "Giraffe", "Owl"];
// Loops through the array to print each zoo animal.
for (var i = 0; i < zooAnimals.length; i++) {
// Logs the animal at index position i to the console. This code is executed each we go through the loop.
console.log(zooAnimals[i]);
}
// We can also do this with a function.
function logArray(list) {
for (var j = 0; j < list.length; j++) {
console.log(list[j]);
}
}
// Produces the same result as the raw loop above.
logArray(zooAnimals);