bhylu.com

Advertisements

JS Loop for

A for loop groups its starting value, test, and update in one place. It suits a known number of repetitions.

Where to run this

This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.

A practical example

JavaScript

for (let seat = 1; seat <= 3; seat += 1) {
  console.log("Seat " + seat);
}

What happens

The output lists seats 1, 2, and 3.