CHAPTER 14
He was not merely a chip of the old block, but the old block itself.
Edmund Burke, On Pitt's First Speech
The sequence of execution of a Java 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 completion 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 abrupt completion.
Blocks are explained first (§14.2), because they can appear in certain places where other kinds of statements are not allowed, and because one other kind of statement, a local variable declaration statement (§14.3), must be immediately contained within a block.
Next a grammatical maneuver is explained that sidesteps the familiar "dangling else
" problem (§14.4).
Statements that will be familiar to C and C++ programmers are the empty (§14.5), labeled (§14.6), expression (§14.7), if
(§14.8), switch
(§14.9), while
(§14.10), do
(§14.11), for
(§14.12), break
(§14.13), continue
(§14.14), and return
(§14.15) statements.
Unlike C and C++, Java has no goto
statement. However, the break
and continue
statements are extended in Java to allow them to mention statement labels.
The Java statements that are not in the C language are the throw
(§14.16), synchronized
(§14.17), and try
(§14.18) statements.
The last section (§14.19) of this chapter addresses the requirement that every statement be reachable in a certain technical sense.