Basic JavaScript Loops (Print-Optimized)


1. The `for` Loop (The Counter)

for (let i = 1; i <= 5; i++) { ... }

2. The `while` Loop (Check First)

let count = 1; while (count <= 5) { ... }

3. The `do...while` Loop (Run Once)

Guarantees it runs once, even if the condition is false.

let x = 10; do { ... } while (x <= 5);

4. The `for...in` Loop (Object Keys)

const pet = { name: "Max", species: "Dog" }; for (let key in pet) { ... }

5. The `for...of` Loop (Array Values)

const colors = ["Red", "Green", "Blue"]; for (let value of colors) { ... }