Concepts·6 / 9

Loops: doing things many times

~5 min read

A loop runs a block of code repeatedly. The two most common loops:

// Count from 1 to 5
for (let i = 1; i <= 5; i++) {
  console.log(i);
}

// Loop through items
let fruits = ['apple', 'banana', 'cherry'];
for (let fruit of fruits) {
  console.log(fruit);
}

Made with Emergent