Summary: Decisions
This lesson summarizes the main points of this chapter.
- A program’s flow of control is the order in which its statements execute.
- An
if
statement tests a Boolean expression and takes a course of action according to whether the expression is true or false. - A statement within an
if
statement executes if a Boolean expression is true. An optionalelse
clause contains a statement that executes when the expression is false. Each of these statements can be compound, that is, a group of statements enclosed in braces. - We use one of the operators
==
,!=
,<
,<=
,>
, or>=
to compare two primitive values. We use the methodequals
to test whether two objects have the same value. Certain objects also have the methodcompareTo
that we can use to compare two objects. - The “and” operator
&&
returns true only when both of its operands are true. The “or” operator||
returns true when one or both of its operands are true. The “not” operator!
changes the value of the Boolean expression to which it applies from true to false or false to true. - An assertion is a statement of truth about some aspect of our program’s logic. In Java, we can add an assertion to our program by writing an
assert
statement.
Get hands-on with 1400+ tech skills courses.