×

javascript · level 1 · unit 5 · lesson 1

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

A does the same job again and again.

Imagine skipping with a rope. You do not write down every jump. You say jump 10 times and off you go. A loop is the same idea: write the lines once, and JavaScript repeats them.

for (let lap = 1; lap <= 3; lap++) has three parts, split by semicolons: where counting starts, the check to keep going, and what happens after each turn. lap++ means : add one to lap.

The lines inside the curly brackets are the loop's block, and they repeat every turn. The first line after the closing } runs once, after the loop has finished.

for (let lap = 1; lap <= 3; lap++) {
  console.log("Lap", lap);
}
console.log("Finished!");

Change the 3 to 100 and the loop runs 100 times, with no extra typing.