Control Flow

There are five basic statements or constructs that modify the control flow of a program:

if-else

do-while

while

for

switch

if-else

The if statement, with an optional else, is a simple construct for conditionally executing a block of code. Here is the basic format:

if(boolean statement)
        // some code
<else>
        <// some code>

Java evaluates the Boolean statement in the if clause. If the clause evaluates to true, the code following the if statement is done. If it is false, the code immediately after the if clause is skipped. You might also optionally supply an else clause. In this case, if the if clause evaluates to true, the code between if and else is performed. If the If clause resolves to false, the code immediately ...

Get PURE Java™ 2 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.