Skip to content

Nested loops and patterns · ⁨嵌套循环与图案⁩

English

A loop inside a loop

  • You can put one loop inside another. The inner loop runs fully for each step of the outer loop.
  • This is how you work with rows and columns, or compare every pair of items.
  • If the outer loop runs R times and the inner runs C times, the inner body runs R × C times.

中文

循环里套循环

  • 你可以把一个循环放进另一个循环里面。外层循环每走一步,内层循环都会完整地跑一遍。
  • 这就是处理行和列、或者比较每一对元素的方法。
  • 如果外层循环跑 R 次,内层跑 C 次,那么内层的代码体一共跑 R × C 次。

一个 3×4 的星号网格:外层循环走行,内层循环走列

Handout

Log in or create account · ⁨登录或创建账户⁩

IGCSE, A-Level · ⁨IGCSE、A-Level⁩ & AP · ⁨与 AP⁩