Guided Notes

Loops

for, while, and do...while loops, break and continue, and for...of / for...in.

Why loops?

Slide 1 / 5

Loops repeat code β€” for each item in a list, a fixed number of times, or until something happens.

Without a loop: text += cars[0]; text += cars[1]; text += cars[2];

With a loop, the same code handles 3 items or 3 million:

for (let i = 0; i < cars.length; i++) { text += cars[i]; }

← Operators & Conditionals