Skip to content

Loop

Easy — everyone uses thisGeneral Dev

ELI5 — The Vibe Check

A loop makes your code do something over and over until a condition says stop. Instead of writing the same line 100 times, you write it once inside a loop and tell it to repeat 100 times. Loops are everywhere — processing lists, animating frames, waiting for input.

Real Talk

A loop is a control flow construct that repeatedly executes a block of code as long as a condition is true or for each item in a collection. Types include for loops (fixed iterations), while loops (condition-based), do-while (runs at least once), for-of (iterables), and for-in (object keys). Loops are the primary mechanism for iterating over data structures.

Show Me The Code

// Different loop types:
const items = ['a', 'b', 'c'];

// for loop:
for (let i = 0; i < items.length; i++) {
  console.log(items[i]);
}

// for-of (preferred for iterables):
for (const item of items) {
  console.log(item);
}

// while loop:
let count = 0;
while (count < 3) {
  console.log(count++);
}

// functional:
items.forEach(item => console.log(item));

When You'll Hear This

"Loop over the array and validate each item." / "There's an infinite loop — it never exits."

Made with passive-aggressive love by manoga.digital. Powered by Claude.