Decisions

3. Decisions#

A business rule becomes useful only when a program chooses the right action for each input. This chapter develops Boolean conditions, alternative branches, and multiway decisions through familiar eligibility and classification problems. You will trace the selected path and check the boundaries where the answer changes.

The examples follow Thistlewood Home and Hardware, a fictional home-improvement retailer with 18 stores (ST-01 to ST-18), an online store that ships to homes or holds orders for store pickup, and a loyalty program, Thistlewood Rewards, with three tiers: Basic, Plus, and Pro (for small contractors). Its everyday rules, such as who ships free, which discount applies, and whether a return is accepted, are the decisions this chapter programs. Policy amounts in the examples are simplified for teaching.

  • Boolean expressions: Conditions evaluate to true or false and drive program decisions.

  • if statements: An if statement runs code only when its condition is true.

  • Multi-branch logic: else if, else, and switch handle several possible cases.

  • Logical operators: Operators such as &&, ||, and ! combine or reverse conditions.

Chapter Video

C# if statements 🤔 (6:27) by Bro Code.

Hosted on YouTube; property of its original creator, embedded here for educational reference only.

Learning Objectives

By the end of this chapter, you will be able to:

  1. Write if, else if, and else chains correctly.

  2. Construct Boolean expressions with comparison and logical operators.

  3. Handle multiple exclusive cases with a switch statement.

  4. Trace which branch executes, including saved Boolean observations and the policy’s decision point.

  5. Avoid common conditional mistakes such as dangling else and boundary errors.

Chapter Flow

Glossary

#

Term

Explanation

1

Conditional statement

A statement that chooses which code to run based on a Boolean condition.

2

Boolean expression

An expression that evaluates to true or false.

3

Comparison operator

An operator such as ==, <, or >= that compares values.

4

If statement

A conditional statement that runs a block when its condition is true.

5

Else branch

A branch that runs when previous conditions in the chain are false.

6

Else-if chain

A sequence of conditional tests that selects among multiple cases.

7

Nested conditional

A conditional statement placed inside another conditional statement.

8

Switch statement

A selection statement that chooses a branch based on matching cases.

9

Case label

A value or pattern used by a switch statement to select code.

10

Default case

The fallback branch of a switch statement.

11

Boundary condition

A value at the edge of a range where conditional mistakes often occur.

12

Boundary case

An input at or near a point where the selected branch changes.

13

Input domain

The set of inputs for which a rule is defined.

14

Complement

A condition true exactly when another condition is false.

15

Truth table

A table listing a Boolean result for every combination of Boolean inputs.

16

Short-circuit evaluation

Skipping a right operand when the left operand already determines the result.

17

Exclusive OR

A Boolean operation true when exactly one of two operands is true.

18

Equivalent implementations

Implementations that preserve the required observable results over the stated input domain.

19

Reevaluation

Computing an expression again using the values available at that point.

20

Eligibility snapshot

A saved eligibility decision for the point in time specified by a policy.

Lecture Slides

Chapter 3 lecture slides follow the current reading order. Supporting parts remain optional; instructor notes and editable decks are distributed separately.