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 optional else 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 method equals to test whether two objects have the same value. Certain objects also have the method compareTo 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 1200+ tech skills courses.