Nested Conditionals - Decisions Within Decisions
8 / 15

What Are Nested Conditionals?

"A conditional inside of a conditional. When we are inside a conditional, we assume that condition is true. Then we can continue to further refine our checks and make more decisions."

The Concept: Narrowing Down

First Decision: Is it raining?
IF raining = True
Second Decision:
IF have_umbrella: walk
ELSE: stay_home
ELSE (not raining)
Just walk outside!
Key Insight: Each level of nesting adds another layer of indentation. The deeper the indent, the more conditions must be True to reach that code.

Interactive Example: Fortress Gate Access Control

Outer Gate: if has_ticket:
Checking ticket...
Inner Gate A: if is_adult:
Not reached
Inner Gate B: elif has_guardian:
Not reached
Check the boxes to see nested logic
CODE EXAMPLES Nested Indentation Structure & Permission Check Example + Explore
age = 16
has_permission = True

if age >= 18:
    # Adult - can decide alone
    print("Access granted (adult)")
else:
    # Not adult - need to check permission (NESTED inside else)
    if has_permission:
        print("Access granted (with permission)")
    else:
        print("Access denied (no permission)")
Mental Model: Think of nested conditionals like a security checkpoint with multiple gates. You only reach the inner gates if you pass the outer ones first.
Meadow Daisies
Woodland Milestone: You've mastered multi-layered decisions! Next, let's discover how to repeat actions automatically with while loops.
Nested conditionals place one check inside another. The inner check only runs when the outer gate is already True.
Wizard Guide