Learn C Programming

Lesson 2 of 7 · Decisions

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

  1. A condition inside a condition
  2. The dangling else: which if owns this else?
  3. Two fixes: braces, or a flatter shape
  4. Flat beats nested: && as the flattening tool
  5. Leave early: return as soon as the answer is known
  6. A nested if that is really a switch