Iteration
In one line
Iteration is the process of repeating a block of code multiple times, typically to process each item in a collection.
In simple words
Iteration means going through something step by step, one item at a time. In programming, it usually means repeating a block of code for each element in a collection (like an array) or a fixed number of times.
The most common iteration tools are for loops, while loops, and for...of / forEach methods. Each takes a block of code and runs it repeatedly, once for each item or until a condition is met.
Iteration is essential for processing collections: summing numbers, filtering items, transforming data, searching for values. Without iteration, you would have to write the same code manually for every element.
Example
const fruits = ["apple", "banana", "cherry"];
// Iteration with for...of
for (const fruit of fruits) {
console.log(fruit);
}
// Output: apple, banana, cherryThe for...of loop iterates over each element in the array, running the block once per item.
Related terms
Related Resources
Related Lessons
- Loops
Learn how loops and iteration work.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.