| English | 意味 |
|---|---|
| nested conditional/ˈnestɪd kənˈdɪʃənl/ | ネスト条件文 |
| three or more/θriː ɔː mɔː/ | 3つ以上 |
| outcomes/ˈaʊtkʌmz/ | 結果 |
| else-if/els ɪf/ | EIF(_page else-if) |
| execution path/ˌeksɪˈkjuːʃn pæθ/ | 実行パス |
| readability/ˌriːdəˈbɪlɪti/ | 可読性 |
When two paths aren't enough
- Sometimes one decision is not enough.
- A nested conditional 嵌套条件语句 places one conditional inside another.
- This lets a program select among three or more 三个或更多 outcomes 结果, not just two.
- Think grades A, B, C, F — four outcomes from one score.
ネストされた条件付き文は、プログラムに以下を可能にします:
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
ネスト化により、単一の IF/ELSE より多くの分岐が追加されます。
ネストされた条件付き文は、3つ以上の可能な ______ の中から選択します。
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
各分岐は異なる結果につながります。
The else-if structure
- A clean way to write this is an else-if 否则如果 structure, testing conditions in sequence:
- IF the first is true, do the first thing;
- ELSE IF the second is true, do the second thing;
- ELSE do the last thing.
成績のための else-if 連鎖
得点をドラッグすると、どの分岐が実行されるか確認できます。else-if 連鎖は上から下へテストを行い、最初に見つかった true の条件の分岐を実行します。
else-if 連鎖は、以下の時点でテストを停止します:
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
最初の true の分岐を選び、残りはスキップします。
プログラムが成績条件をチェックする順序を並べ替えてください。
難易度 3/5 · 200 コイン + 今日初回完了時に小ボーナス付与
上から下へテストを行い、最初に見つかった true の所で停止します。
Trace the path
- The program checks conditions from top to bottom.
- It stops at the first one that is true.
- To understand nested conditionals, trace the execution path 执行路径 for given inputs.
- Follow each true-or-false result to see which branch wins.
成績の連鎖(≥90 A, ≥80 B, ≥70 C, else F)において、得点 85 は以下になります:
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
85 ≥ 90 は false;85 ≥ 80 は true → "B"、そしてテストは停止します。
深くネストされた条件付き文を簡素化することは、可読性を向上させ、エラーを減らします。
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
少ない、明確な分岐の方が正しく記述しやすいです。
Keep it readable
- Deeply nested logic can become hard to read.
- Simplify overly complex nesting to improve readability 可读性 and reduce errors.
Score to grade. IF score ≥ 90 → "A"; ELSE IF ≥ 80 → "B"; ELSE IF ≥ 70 → "C"; ELSE → "F". For score 85: 85 ≥ 90 is false, so move on; 85 ≥ 80 is true → grade "B", and testing stops. Order matters — we already know it is below 90.
A nested conditional chooses among three or more outcomes, usually with an else-if chain that tests top to bottom and stops at the first true condition. Trace the execution path to find which branch runs (score 85 → "B"), and keep nesting shallow for readability.