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.
Checking what this lesson needs for you…
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