C27 · Topic 3.6 · 40 minutes · AAP-2.G, AAP-2.H
Choosing a branch
By the end you can:
- Trace IF and IF/ELSE.
- Distinguish independent conditions from exclusive branches.
- Predict all displayed outputs in order.
Before this lesson: topics 3.5.
- Selection
- Choosing which statements execute based on a condition.
- Branch
- A path through conditional code.
Understand
An IF executes its body only when its condition is true. An IF/ELSE chooses exactly one of its two branches. Two separate IF statements are not automatically exclusive: both may execute, depending on the current state and conditions.
Write down every output in sequence. Reading only the first true condition or assuming an unstated ELSE can miss later effects. If the first branch changes a variable, evaluate the next condition using that updated state rather than assuming all conditions were tested at once.
Worked example
x←7;IF(x>3){DISPLAY("A")};IF(x<10){DISPLAY("B")}.
- 7>3 is true, so A displays.
- x is unchanged by DISPLAY.
- 7<10 is also true, so B displays after A.
Explore each concept
Choose a concept, change its inputs and follow the explanation. Each example models the stated rule or scenario; completing it is practice rather than evidence of mastery.
- Multiple outputs in order
- Exclusive branches
- Inverted equivalent conditions
Change it · step through · explain
Change an input, predict what will happen, then advance one step. Read why the state changes, reset and experiment. This fixed teaching model does not save progress or award XP.
Ready · Make a prediction
- Score (0–100)85Waiting
- Structureindependent-IFsWaiting
Ready to explore: Independent IFs versus IF/ELSE
Why: Change an input, predict the first effect, then advance one step.
Try this: Change one input or choose another listed case. Predict the effect, reset and compare the states and governing rule.
Step through and experiment
Change it · step through · explain
Change an input, predict what will happen, then advance one step. Read why the state changes, reset and experiment. This fixed teaching model does not save progress or award XP.
Ready · Make a prediction
- Input 114Waiting
- Input 20Waiting
Ready to experiment
Why: Predict the first change, then advance one step.
Try this: Compare ages 13 and 14 with places 0 and 1.
Check a misconception
Claim: Only the first true IF in a programme can run.
Independent IF statements are evaluated separately; an IF/ELSE pair is a different structure.
Guided practice
Replace the two independent IFs with IF(x>3){A}ELSE{B}. Predict x 7.
Work with a partner. Make a prediction, compare your reasoning, then identify the rule that supports your answer.
Independent transfer
Trace x 4;IF(x>3){x←12};IF(x<10){DISPLAY("B")}.
Exit check
Why should conditional traces show intermediate state?
Write your reasoning before comparing with a classmate. If your teacher assigned this task, submit it through My classes to save your work and receive feedback.
Check yourself
Your practice so far
Check an answer to see its rationale.