Java Reference
In-Depth Information
Chapter 14. Blocks and Statements
The sequence of execution of a program is controlled by
statements
, which are executed for
their effect and do not have values.
Some statements
contain
other statements as part of their structure; such other statements
are substatements of the statement. We say that statement
S immediately contains
statement
U
if there is no statement
T
different from
S
and
U
such that
S
contains
T
and
T
contains
U
.
In the same manner, some statements contain expressions (§15) as part of their structure.
The first section of this chapter discusses the distinction between normal and abrupt com-
statements, describing in detail both their normal behavior and any special treatment of ab-
rupt completion.
variable declaration statements (§
14.4
).
Next a grammatical maneuver that sidesteps the familiar “dangling else” problem (§
14.5
) is
explained.
The last section (§
14.21
) of this chapter addresses the requirement that every statement be
reachable
in a certain technical sense.
14.1. Normal and Abrupt Completion of Statements
Every statement has a normal mode of execution in which certain computational steps are
carried out. The following sections describe the normal mode of execution for each kind of
statement.
If all the steps are carried out as described, with no indication of abrupt completion, the
statement is said to
complete normally
. However, certain events may prevent a statement
from completing normally:
of control that may prevent normal completion of statements that contain them.
• Evaluation of certain expressions may throw exceptions from the Java Virtual
An exception causes a transfer of control that may prevent normal completion of
statements.