| *Chapter 14* |
| |
| h1. Blocks and Statements |
| The organization of this chapter parallels the chapter on [Blocks and Statements|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html] in the [Java Language Specification (second edition)|http://java.sun.com/docs/books/jls/second_edition/html/j.title.doc.html], which begins as follows: |
| |
| bq. The sequence of execution of a program is controlled by ??statements??, which are executed for their effect and do not have values. |
| |
| bq. 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|Chapter 15 Expressions#15], [JLS|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#4709]) as part of their structure. |
| |
| bq. The first section of this chapter discusses the distinction between normal and abrupt completion of statements ([§14.1|Chapter 14 Blocks#14.1], [JLS|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#5894]). 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. |
| |
| bq. Blocks are explained first ([§14.2|Chapter 14 Blocks#14.2], [JLS|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#246838]), followed by local class declarations ([§14.3|Chapter 14 Blocks#14.3], [JLS|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#247766]) and local variable declaration statements ([§14.4|Chapter 14 Blocks#14.4], [JLS|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#5920]). |
| |
| bq. Next a grammatical maneuver that sidesteps the familiar "dangling {{else}}" problem ([§14.5|Chapter 14 Blocks#14.5], [JLS|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#32584]) is explained. |
| |
| bq. Statements that will be familiar to C and C++ programmers are the empty ([§14.6|Chapter 14 Blocks#14.6], [JLS|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#5970]), labeled ([§14.7|Chapter 14 Blocks#14.7], [JLS|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#78993]), expression ([§14.8|Chapter 14 Blocks#14.8], [JLS|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#5984]), {{if}} ([§14.9|Chapter 14 Blocks#14.9], [JLS|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#5991]), {{switch}} ([§14.10|Chapter 14 Blocks#14.10], [JLS|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#35518]), {{while}} ([§14.11|Chapter 14 Blocks#14.11], [JLS|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#237277]), {{do}} ([§14.12|Chapter 14 Blocks#14.12], [JLS|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#6045]), {{for}} ([§14.13|Chapter 14 Blocks#14.13], [JLS|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#24588]), {{break}} ([§14.14|Chapter 14 Blocks#14.14], [JLS|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#6842]), {{continue}} ([§14.15|Chapter 14 Blocks#14.15], [JLS|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#6122]), and {{return}} ([§14.16|Chapter 14 Blocks#14.16], [JLS|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#6767]) statements. |
| |
| bq. Unlike C and C++, the Java programming language has no {{goto}} statement. However, the {{break}} and {{continue}} statements are allowed to mention statement labels. |
| |
| bq. The Java programming language statements that are not in the C language are the {{throw}} ([§14.17|Chapter 14 Blocks#14.17], [JLS|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#237350]), {{synchronized}} ([§14.18|Chapter 14 Blocks#14.18], [JLS|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#255769]), and {{try}} ([§14.19|Chapter 14 Blocks#14.19], [JLS|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#79311]) statements. |
| |
| bq. The last section ([§14.20|Chapter 14 Blocks#14.20], [JLS|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#236365]) of this chapter addresses the requirement that every statement be ??reachable?? in a certain technical sense. |
| |
| {anchor:14.1} |
| h2. 14.1 Normal and Abrupt Completion of Statements |
| (Cf. ??[JLS. §14.1|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#5894]??.) |
| |
| TO DO |
| |
| {anchor:14.2} |
| h2. 14.2 Blocks |
| (Cf. ??[JLS. §14.2|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#246838]??.) |
| |
| TO DO |
| |
| {anchor:14.3} |
| h2. 14.3 Local Class Declarations |
| (Cf. ??[JLS. §14.3|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#247766]??.) |
| |
| TO DO |
| |
| {anchor:14.4} |
| h2. 14.4 Local Variable Declaration Statements |
| (Cf. ??[JLS. §14.4|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#5920]??.) |
| |
| TO DO |
| |
| {anchor:14.4.1} |
| h3. 14.4.1 Local Variable Declarators and Types |
| (Cf. ??[JLS. §14.4.1|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#35393]??.) |
| |
| TO DO |
| |
| {anchor:14.4.2} |
| h3. 14.4.2 Scope of Local Variable Declarations |
| (Cf. ??[JLS. §14.4.2|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#32644]??.) |
| |
| TO DO |
| |
| {anchor:14.4.3} |
| h3. 14.4.3 Shadowing of Names by Local Variables |
| (Cf. ??[JLS. §14.4.3|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#32716]??.) |
| |
| TO DO |
| |
| {anchor:14.4.4} |
| h3. 14.4.4 Execution of Local Variable Declarations |
| (Cf. ??[JLS. §14.4.4|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#32717]??.) |
| |
| TO DO |
| |
| {anchor:14.5} |
| h2. 14.5 Statements |
| (Cf. ??[JLS. §14.5|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#32584]??.) |
| |
| TO DO |
| |
| {anchor:14.6} |
| h2. 14.6 The Empty Statement |
| (Cf. ??[JLS. §14.6|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#5970]??.) |
| |
| TO DO |
| |
| {anchor:14.7} |
| h2. 14.7 Labeled Statements |
| (Cf. ??[JLS. §14.7|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#78993]??.) |
| |
| TO DO |
| |
| {anchor:14.8} |
| h2. 14.8 Expression Statements |
| (Cf. ??[JLS. §14.8|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#5984]??.) |
| |
| TO DO |
| |
| {anchor:14.9} |
| h2. 14.9 The <code>if Statement</h2> |
| (Cf. ??[JLS. §14.9|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#5991]??.) |
| |
| TO DO |
| |
| {anchor:14.9.1} |
| h3. 14.9.1 The <code>if-then Statement</h3> |
| (Cf. ??[JLS. §14.9.1|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#237433]??.) |
| |
| TO DO |
| |
| {anchor:14.9.2} |
| h3. 14.9.2 The <code>if-then-else Statement</h3> |
| (Cf. ??[JLS. §14.9.2|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#236506]??.) |
| |
| TO DO |
| |
| {anchor:14.10} |
| h2. 14.10 The <code>switch Statement</h2> |
| (Cf. ??[JLS. §14.10|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#35522]??.) |
| |
| TO DO |
| |
| {anchor:14.11} |
| h2. 14.11 The while Statement |
| (Cf. ??[JLS. §14.11|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#237278]??.) |
| |
| TO DO |
| |
| {anchor:14.11.1} |
| h3. 14.11.1 Abrupt Completion |
| (Cf. ??[JLS. §14.11.1|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#21139]??.) |
| |
| TO DO |
| |
| {anchor:14.12} |
| h2. 14.12 The do Statement |
| (Cf. ??[JLS. §14.12|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#246911]??.) |
| |
| TO DO |
| |
| {anchor:14.12.1} |
| h3. 14.12.1 Abrupt Completion |
| (Cf. ??[JLS. §14.12.1|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#45366]??.) |
| |
| TO DO |
| |
| {anchor:14.12.2} |
| h3. 14.12.2 Example of do statement |
| (Cf. ??[JLS. §14.12.2|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#252264]??.) |
| |
| TO DO |
| |
| {anchor:14.13} |
| h2. 14.13 The <code>for Statement</h2> |
| (Cf. ??[JLS. §14.13|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#24588]??.) |
| |
| TO DO |
| |
| {anchor:14.13.1} |
| h3. 14.13.1 Initialization of <code>for statement</h3> |
| (Cf. ??[JLS. §14.13.1|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#45367]??.) |
| |
| TO DO |
| |
| {anchor:14.13.2} |
| h3. 14.13.2 Iteration of for statement |
| (Cf. ??[JLS. §14.13.2|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#217196]??.) |
| |
| TO DO |
| |
| {anchor:14.13.3} |
| h3. 14.13.3 Abrupt Completion of <code>for statement</h3> |
| (Cf. ??[JLS. §14.13.3|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#45371]??.) |
| |
| TO DO |
| |
| {anchor:14.14} |
| h2. 14.14 The <code>break Statement</h2> |
| (Cf. ??[JLS. §14.14|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#35540]??.) |
| |
| TO DO |
| |
| {anchor:14.15} |
| h2. 14.15 The <code>continue Statement</h2> |
| (Cf. ??[JLS. §14.15|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#6122]??.) |
| |
| TO DO |
| |
| {anchor:14.16} |
| h2. 14.16 The <code>return Statement</h2> |
| (Cf. ??[JLS. §14.16|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#6767]??.) |
| |
| TO DO |
| |
| {anchor:14.17} |
| h2. 14.17 The <code>throw Statement</h2> |
| (Cf. ??[JLS. §14.17|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#237350]??.) |
| |
| TO DO |
| |
| {anchor:14.18} |
| h2. 14.18 The <code>synchronized Statement</h2> |
| (Cf. ??[JLS. §14.18|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#255769]??.) |
| |
| TO DO |
| |
| {anchor:14.19} |
| h2. 14.19 The <code>try statement</h2> |
| (Cf. ??[JLS. §14.19|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#79311]??.) |
| |
| TO DO |
| |
| {anchor:14.19.1} |
| h3. 14.19.1 Execution of try-catch<code><b></code></h3> |
| (Cf. ??[JLS. §14.19.1|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#24134]??.) |
| |
| TO DO |
| |
| {anchor:14.19.2} |
| h3. 14.19.2 Execution of try-catch-finally<code><b></code></h3> |
| (Cf. ??[JLS. §14.19.2|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#79326]??.) |
| |
| TO DO |
| |
| {anchor:14.20} |
| h2. 14.20 Unreachable Statements |
| (Cf. ??[JLS. §14.20|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#236365]??.) |
| |
| TO DO |
| |
| ---- |
| Specification [Table of Contents|Chapter 00 Contents]. |
| |
| The organization of this chapter parallels the chapter on [Blocks and Statements|http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html] in the [Java Language Specification (second edition)|http://java.sun.com/docs/books/jls/second_edition/html/j.title.doc.html]. |
| |
| The original of this specification is at [http://docs.codehaus.org/display/GroovyJSR]. |