JavaScript - For Loop

Overview

Estimated time: 15–25 minutes

The classic for loop iterates using an initializer, condition, and update expression.

Learning Objectives

  • Write counting and index-based loops.
  • Use break and continue effectively.

Prerequisites

Examples

for (let i = 0; i < 3; i++) {
  console.log(i);
}

// Early exit
for (let i = 0; i < 10; i++) {
  if (i === 3) break;
}

Common Pitfalls

  • Off-by-one errors in loop bounds.