| English | 意味 |
|---|---|
| conditional/kənˈdɪʃənl/ | 条件分岐 |
| block/blɒk/ | コードブロック |
| if/ɪf/ | if |
| else/els/ | else |
| clause/klɔːz/ | 節 |
| selection/sɪˈlekʃn/ | 選択 |
| iteration/ˌɪtəˈreɪʃn/ | 反復 |
| branch/bræntʃ/ | 分岐 |
| Boolean condition/ˈbuːlɪən kənˈdɪʃn/ | ブール条件 |
Choosing what to do
- A conditional 条件语句 runs a block 代码块 of code only when a condition is true.
- This lets a program choose what to do based on data.
- Different inputs can send the program down different paths.
- It is one of the three building blocks of every program.
条件付き文は、コードのブロックを以下のように実行します:
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
条件がブロックの実行の有無を決定します。
IF/ELSEにおいて、毎回いくつの分岐が実行されますか?
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
条件が1つの分岐を選び、もう片方はスキップされます。
IF and ELSE
- The basic form is an if 如果 statement, often with an else 否则 clause 子句:
- IF the condition is true, run the first block;
- ELSE (the condition is false), run the second block.
- Exactly one block runs each time.
選択:IF / ELSE の分岐に従う
得点をドラッグすると、どの分岐が実行されるか確認できます。IFは条件をテストし、条件が真の場合最初のブロックを実行し、そうでない場合は ELSE ブロックを実行します—どちらか片方だけが実行されます。
条件に基づいてパスを選択することを ______ といいます。
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
選択は、順次処理と反復処理と共に、3つの基本構造の一つです。
Selection
- This ability to choose between paths is called selection 选择.
- Selection is one of three building blocks, with sequencing and iteration 迭代.
- To understand a conditional, trace which branch 分支 runs for a given input.
- Only one branch runs, chosen by the condition.
IF isMember: price ← price × 0.9。isMember が true で price が 100 の場合、price は以下になります:
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
IF分岐が実行され、100 × 0.9 = 90 となります。
isMember が false の場合、ELSE分岐が実行され、price は 100 のままです。
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
条件が false の場合、ELSEブロックが実行されます。
不適切なブール条件を書くことは通常、以下を引き起こします:
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
誤った条件は、プログラムを誤った分岐へと導きます。
Get the condition right
- Make sure the Boolean condition 布尔条件 correctly captures the intended rule.
- A wrong condition is a common source of logic errors.
Member discount. IF isMember is true: price ← price × 0.9; ELSE: price stays the same. With isMember true and price 100, the IF branch runs → price becomes 90. If false, the ELSE branch runs → price stays 100.
A conditional runs a block only when a condition is true. An IF with an ELSE picks exactly one of two paths — this is selection, one of the three building blocks. Trace which branch runs for each input, and make sure the Boolean condition matches the rule you intended.