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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access