nested loop(嵌套循环):在一个循环结构的循环体内再包含另一个循环(甚至多层循环)。常用于处理二维/多维数据、生成组合、遍历表格或矩阵等。编程语境中也常提示时间复杂度可能增加(例如从 (O(n)) 变为 (O(n^2)))。
/ˈnɛstɪd luːp/
A nested loop prints a 10-by-10 multiplication table.
嵌套循环可以打印一张 10×10 的乘法表。
Because the algorithm uses a nested loop to compare every pair of items, its running time grows quickly as the list gets larger.
由于该算法用嵌套循环来比较每一对元素,列表越大运行时间增长越快。
nested 来自 nest(“巢”),引申为“像套在巢里一样层层包裹、置于内部”;loop 原意为“环、圈”,在计算机语境中表示“循环执行的一段结构”。合起来 nested loop 形象地表达“循环里面再套一个循环”。
for 循环嵌套来处理表格、字符或数组遍历。