Iteration
一句话解释
Iteration 是处理的 repeating 块的 code 多个次数, 典型地到 处理每个项 in 集合.
用大白话说
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, 虽然 loops, and for...的 / 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.
示例
const fruits = ["apple", "banana", "cherry"];
// Iteration with for...of
for (const fruit of fruits) {
console.log(fruit);
}
// Output: apple, banana, cherryfor...的循环 iterates over 每个元素 in 数组, 运行块 一次每 项.
相关术语
相关资源
相关课程
- 循环
学习如何循环 and iteration 工作.
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。