CHAPTER 3
DECISIONS 
CHAPTER GOALS
To implement decisions using if statements
To compare integers, floating-point numbers, and strings
To write statements using the Boolean data type
To develop strategies for testing your programs
To validate user input
CHAPTER CONTENTS
Programming Tip 3.1: Brace Layout
Programming Tip 3.2: Always Use Braces
Common Error 3.1: A Semicolon After the if Condition
Special Topic 3.1: The Conditional Operator
Programming Tip 3.4: Avoid Duplication in Branches
3.2 COMPARING NUMBERS AND STRINGS
Common Error 3.2: Exact Comparison of Floating-Point Numbers
Common Error 3.3: Using == to Compare Strings
Special Topic 3.2: Lexicographic Ordering of Strings
How To 3.1: Implementing an if Statement
Worked Example 3.1: Extracting the Middle ![]()
Random Fact 3.1: The Denver Airport Luggage Handling System
Special Topic 3.3: The switch Statement
Programming Tip 3.5: Hand-Tracing
Common Error 3.4: The Dangling else Problem
Special Topic 3.4: Enumeration Types
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access