| English | 意味 |
|---|---|
| loop/luːp/ | ループ |
| repeat/rɪˈpiːt/ | 反復 |
| Iteration/ˌɪtəˈreɪʃn/ | 反復 |
| until/ʌnˈtɪl/ | until(page until) |
| infinite loop/ˈɪnfɪnət luːp/ | 無限ループ |
| iterations/ˌɪtəˈreɪʃnz/ | 反復処理 |
Loops repeat work
- Iteration 迭代 repeats a block of code using a loop 循环.
- Loops let a short program do a large amount of work.
- Instead of writing the same line 100 times, you loop it 100 times.
- It is the third building block, with sequencing and selection.
ループを使ってコードのブロックを繰り返すことを ______ といいます。
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
反復により、短いプログラムでも多くの作業を行うことができます。
ループにより、短いプログラムでも大量の反復作業を行うことができます。
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
これが反復の目的そのものです。
Two kinds of loop
- A repeat 重复 loop runs a block a fixed number of times — "REPEAT 10 TIMES" runs it ten times.
- A condition-controlled loop keeps running until 直到 a condition becomes true (or while one stays true).
- Its number of repetitions depends on the data, not a fixed count.
各ループを、それを制御する要素とペアにしてください。
難易度 2/5 · 140 コイン + 今日初回完了時に小ボーナス付与
REPEAT 10 TIMES は固定数です;UNTIL はデータに依存します。
無限ループは以下の場合に発生します:
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
内部の何かが終了条件に向かって動く必要があります。
Beware the infinite loop
- A serious danger is an infinite loop 无限循环 — a loop that never meets its stopping condition.
- The program then runs forever.
- To avoid it, make sure something inside the loop moves toward the stopping condition.
- Usually that means a counter that changes each pass.
ループをトレースし、パスごとに確認する
トレーステーブルは、各パス後に各変数の値を記録します。i が上昇しながら累積和が積み上がっていく様子を見ながら、i が 4 を超えた時点でループが停止することを確認してください。
ループが sum に 1, 2, 3, 4 を加算します(初期値は 0)。最終的な sum は幾つですか?
難易度 2/5 · 140 コイン + 今日初回完了時に小ボーナス付与
1 + 2 + 3 + 4 = 10.
sum ループにおいて、無限ループにならないようにしている行はどれですか?
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
i = i + 1 がない場合、i は 4 を超えず、ループは永遠に続きます。
Trace the iterations
- To understand a loop, trace the variables across its iterations 迭代过程, one pass at a time.
Sum 1 to 4. Start sum = 0, i = 1. REPEAT UNTIL i > 4: add i to sum, then i = i + 1. Trace: sum 1 (i→2), 3 (i→3), 6 (i→4), 10 (i→5). Now 5 > 4, so it stops. Final sum = 10. The line i = i + 1 is what keeps it from being infinite.
Iteration repeats a block with a loop, so a short program does a lot of work. A repeat loop runs a fixed count; a condition-controlled loop runs until a condition is met. Beware the infinite loop — always move toward the stop. Trace the variables across iterations (sum 1..4 = 10).