5.2 Simple Selection with if

The simple selection pattern is appropriate when our program needs to perform an operation for one set of data, but not for all other data. For this situation, we use a simple if statement, which has this pattern:

if ( condition )
  true block
next statement

The true block can contain one or more statements and is executed only if the condition evaluates to true. After the true block executes, the instruction following the if statement is executed. If the condition is false, the true block is skipped and execution picks up at the next instruction after the if statement. If the true block contains only one statement, the curly braces are optional. Figure 5.2 illustrates the flow of control of a simple if statement. ...

Get Java Illuminated, 5th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.