Chapter 6
Making Choices
IN THIS CHAPTER
Boring into Boolean expressions for fun and profit
Focusing on your basic, run-of-the-mill if statement
Looking at else clauses and else-if statements
Considering logical operators
Using the switch statement
So far in this book, all the programs have run straight through from start to finish without making any decisions along the way. In this chapter, you discover two Java statements that let you create some variety in your programs. The if statement lets you execute a statement or a block of statements only if some conditional test turns out to be true. And the switch statement lets you execute one of several blocks of statements depending on the value of an integer variable.
Using Simple Boolean Expressions
All if statements, as well as several of the other control statements that we describe in Chapter 7 (while, do, and for), use Boolean expressions to determine whether to execute or skip a statement (or a block of statements). A Boolean ...
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