Module 5 · Decisions
Nested Conditions and the Dangling else
Free with an accountReading
Bob's shop has a simple rule. Members who spend 1000 or more get 20 percent off. Every customer who is not a member gets a 5 percent welcome coupon.
Sign in to read
This lesson is free, with an account
An account costs nothing and opens every lesson in this track that is not marked Pro, on every device you read on.
What is inside Nested Conditions and the Dangling else
- A condition inside a condition
- The dangling else: which if owns this else?
- Two fixes: braces, or a flatter shape
- Flat beats nested: && as the flattening tool
- Leave early: return as soon as the answer is known
- A nested if that is really a switch