Control Flow Functions

Control flow is the heart of any program. It is the capability to adjust (control) the way that a program progresses (flows). By directing the paths of execution that your code takes, you build programs that behave dynamically based on their inputs. Without control flow, programs would not be able to do anything more than several sequential operations.

if Statements

The simplest form of control flow is the if statement. An if statement checks its conditional expression (typically derived through any of the means described in the first half of this chapter) and, if the value is true, directs the interpreter to execute the next block of code. The general syntax for the if statement is as follows:

 if (expression) statement; ...

Get Special Edition Using Java 2 Standard 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.