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
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.
Woodland Milestone: You've mastered multi-layered decisions! Next, let's discover how to repeat actions automatically with while loops.