JavaScript Loops

// The 'for' loop
for (let i = 1; i <= 5; i++) {
  console.log(i);
}
                

Start: let i = 1 (Where to begin)

Condition: i <= 5 (Keep going as long as...)

Increment: i++ (How to change each time)

Automation

Loops are used to **repeat a block of code** multiple times. Instead of writing 5 separate console.log lines, the loop handles the repetition for you.

This is extremely useful for displaying lists of data, creating multiple elements, or processing items in an array.