For Loops

  • "For-loops" are for iterating a specific number of times
  • There are a couple syntaxes. One is for iterating over a known set of items. The other is a bit more flexible
const myFavoriteNumbers = [1,2,3];
// Create a variable called "number" for each element in myFavoriteNumbers
for(const number of myFavoriteNumbers) {
    console.log(number);
}

// Iterate from 0 to 4
for(let i = 0; i < 5; i++) {
    console.log("Here is a number: " + i)
}

9 / 24