Loop
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."
Related Terms
Algorithm
An algorithm is just a step-by-step recipe for solving a problem. Sort a list? There is an algorithm. Find the shortest path? Algorithm. Make a sandwich?
Array
An array is a list of things in order, like a numbered row of boxes. Box 0 holds the first item, box 1 holds the second, and so on.
Conditional
A conditional is an if/else decision in your code — 'if this is true, do this; otherwise, do that.' It is how your program makes choices.
Recursion
Recursion is when a function calls itself to solve a smaller version of the same problem, like a set of Russian nesting dolls.