Java Reference
In-Depth Information
Chapter 9
Directing Program Flow
Simple Decisions
The main difference between a computer and a calculating machine is that
the computer can make simple decisions. Programs are able to process in-
formation logically because of this decision-making ability. The result of a
program decision is to direct program execution in one direction or an-
other one, that is, to change program flow. One of the most important tasks
performed by the programmer is the implementation of the program's pro-
cessing logic. This implementation is by means of the language's decision
constructs. In this chapter you will learn how a Java program makes deci-
sions.
Java Decisions Constructs
To make a program decision requires several language elements. Suppose
an application that must determine if the variable a is larger than b . If this is
the case, the program must take one course of action. If both variables are
equal, or if b is larger than a , then another course of action is necessary. As
you can see, the program has to make a comparison, examine the results,
andtakethecorrespondingactionineachcase.Allofthiscannotbeaccom-
plished with a single operator or keyword, but requires one or more expres-
sions contained in one or more statements. For this reason we talk about
decision statements and decision constructs. In programming, a construct
can be described as one or more expressions, contained in one or more
statements, all of which perform a specific action.
Java contains several high-level decision operators and keywords that
can be used in constructs which make possible selection between several
processing options. The major decision-making mechanisms are called
Search WWH ::




Custom Search