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-
pletion of statements (§ 14.1 ) . Most of the remaining sections explain the various kinds of
statements, describing in detail both their normal behavior and any special treatment of ab-
rupt completion.
Blocks are explained first (§ 14.2 ) , followed by local class declarations (§ 14.3 ) and local
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:
• The break 14.15 ), continue 14.16 ) , and return 14.17 ) statements cause a transfer
of control that may prevent normal completion of statements that contain them.
• Evaluation of certain expressions may throw exceptions from the Java Virtual
Machine (§ 15.6 ) . An explicit throw 14.18 ) statement also results in an exception.
An exception causes a transfer of control that may prevent normal completion of
statements.
Search WWH ::




Custom Search