Concept
Nested if Statements
You can place `if` blocks inside other `if` blocks:
python
if is_vip:
if has_ticket:
print("Welcome inside!")
# 52. Nested if Statements You can place `if` blocks inside other `if` blocks: ```python if is_vip: if has_ticket: print("Welcome inside!") ``` Warning: Nesting 5 levels deep creates the "Pyramid of Doom." Keep your logic flat whenever possible using `and`: `if is_vip and has_ticket:`.
Checkpoint
Why do developers avoid nesting 5 `if` blocks inside each other?
Practice
Write a nested `if` that checks `has_key = True`. Inside it, check `knows_pin = True`. If both are true, print `"Vault opened"`.
01
Tap code blocks below to assemble
Available Blocks