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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.