Conditionals
導入済み
9:10
アルゴリズムとプログラミング
1百万名の名前が入った電話帳を想像し、その中から1人を見つける必要があるとしよう。一つずつ確認していくと、一日中かかってしまうかもしれない。約…で見つける方法がある。
英語のナレーション・英語と中国語の字幕を切り替え可能
このレッスンの内容
| English | 意味 |
|---|---|
| conditional/kənˈdɪʃənl/ | 条件分岐 |
| block/blɒk/ | コードブロック |
| if/ɪf/ | |
| else/els/ | |
| 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 条件语句 uses a condition to decide which block 代码块 of code to run.
- 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.
The IF block of a conditional statement runs:
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
The condition decides whether the block runs.
In an IF/ELSE, how many branches run each time?
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
The condition chooses one branch; the other is skipped.
IFとELSE
- 基本形はif文であり、多くの場合else節が含まれます:
- IF条件が真の場合、最初のブロックを実行;
- ELSE(条件が偽の場合)、2番目のブロックを実行。
- 毎回必ず1つのブロックのみが実行されます。

条件に基づいてパスを選択する

Selection: follow the IF / ELSE branch
Drag the score and watch which branch runs. An IF tests the condition and takes the first block if true, otherwise the ELSE block — only one runs.
Choosing between paths based on a condition is called ______.
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
Selection is one of the three building blocks, with sequencing and iteration.
選択
- この経路間の選択機能を選択構造と呼びます。
- 選択構造は、順次処理と反復処理を含む3つの構成要素の一つです。
- 条件分岐を理解するには、与えられた入力でどの枝が実行されるかをトレースする必要があります。
- 条件によって選ばれた1つの枝のみが実行されます。
IF isMember: price ← price × 0.9. With isMember true and price 100, price becomes:
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
The IF branch runs: 100 × 0.9 = 90.
If isMember is false, the IF branch runs and the member discount is applied.
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
False. A false condition skips the IF block and runs the ELSE branch, so the price stays 100.
Writing the wrong Boolean condition usually causes:
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
A wrong condition sends the program down the wrong branch.
正確な条件を設定する
- ブール条件が意図したルールを正しく表現しているか確認してください。
- 誤った条件はロジックエラーの一般的な原因となります。
メンバー割引。 IF isMember が真の場合:price ← price × 0.9;ELSE:price はそのまま。isMember が真で価格が 100 の場合、IF分支が実行 → 価格は 90 に。偽の場合、ELSE分支が実行 → 価格は 100 のまま。
条件付き分岐は、条件が真である場合にのみブロックを実行します。IF文にELSE文を組み合わせると、2つの経路のうち1つだけを正確に選択することになります。これは選択構文と呼ばれ、プログラミングの3大基本構成要素の一つです。各入力に対してどの枝が実行されるかをトレースし、ブール式が意図したルールと一致しているか確認してください。
何が問題でしたか?この内容はサイトの運営チームだけが確認します。