ABSTRACT

This chapter describes the powerful principle of selection, which enables us to specify actions that to be performed when certain conditions are true. It helps to learn about the basic if statement, as well as its if-else and if-else-if-else forms. The chapter then explores Boolean expressions, such as those used in the condition of an if statement, and how to create them using the comparison (relational) operators: <,>, <=, >=, ==, and !=. It explains how to create compound Boolean expressions using the AND (&&) and OR (||) operations. It also explains Boolean variables and how they can be used to store conditions. The chapter further helps to learn about the switch statement, which can take the place of if-else-if-else structures when mutually exclusive conditions are required. Reliably testing for equality of String objects using the equals() method is also described in the chapter.