← Back to Roadmap

For Loop

Easy

In plain terms

The for loop has initialization, condition, and update: for (init; condition; update). Ideal when you know how many times to iterate. Most common loop for arrays and counts.

What you need to know

  • init; condition; update
  • Block-scoped loop variable
  • Classic iteration pattern

Try it yourself

Copy the code below and run it in your browser console or a code editor:

for (let i = 0; i < 5; i++) {
  console.log(i);  // 0, 1, 2, 3, 4
}

for (let i = 0; i < arr.length; i++) {
  console.log(arr[i]);
}

// Countdown
for (let i = 10; i >= 0; i--) {
  console.log(i);
}

Learn more

Dive deeper with these trusted resources: