C29 · Topic 3.7 · 40 minutes · AAP-2.I
Decisions inside decisions
By the end you can:
- Trace an outer decision before its inner decision.
- Identify mutually exclusive paths.
- Predict one output from a complete nested tree.
Before this lesson: topics 3.6.
- Nested conditional
- A conditional statement inside a branch of another conditional.
- Reachability
- Whether a path or statement can execute under the stated conditions.
Understand
A nested conditional is evaluated only after execution reaches the branch containing it. If the outer condition selects a different branch, conditions inside the skipped branch do not decide the result. Trace the path from the outside inward instead of scanning for a true expression anywhere in the code.
A complete two-level IF/ELSE tree can express four distinct combinations, but each run follows one path. Conditions can depend on earlier state changes, so name which comparisons were actually reached. The visual indentation helps communicate structure; the branch boundaries determine behaviour.
Worked example
A fictional route selector tests wet first, then stepFree inside either branch.
IF (wet)
{ IF (stepFree) { DISPLAY("Covered ramp") }
ELSE { DISPLAY("Covered stairs") } }
ELSE
{ IF (stepFree) { DISPLAY("Outdoor ramp") }
ELSE { DISPLAY("Outdoor steps") } }- wet true selects the covered branch.
- Within that branch, stepFree false selects stairs.
- Only Covered stairs displays; the outdoor branch is not reached.
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.
- Outer branch before inner branch
- Unreachable conditions
- Path coverage
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
- Age (0–100)17Waiting
- Inner conditionage<12Waiting
Ready to explore: Reachable and contradictory nested paths
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 1yesWaiting
- Input 2noWaiting
Ready to experiment
Why: Predict the first change, then advance one step.
Try this: Try all four yes/no combinations. These fictional labels are not accessibility guarantees.
Check a misconception
Claim: Any true inner condition can override a false outer condition.
An inner condition matters only when its containing branch executes.
Guided practice
Trace wet false, stepFree true.
Work with a partner. Make a prediction, compare your reasoning, then identify the rule that supports your answer.
Independent transfer
Describe the path for wet true, stepFree true without referring to a skipped branch as executed.
Exit check
Why is indentation alone insufficient evidence of the path?
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.