Statements
A statement is a single command executed by the Java interpreter. By default, the Java interpreter runs one statement after another, in the order they are written. Many of the statements defined by Java, however, are flow-control statements, such as conditionals and loops, that alter this default order of execution in well-defined ways. Table 2-5 summarizes the statements defined by Java.
Table 2-5. Java statements
Statement |
Purpose |
Syntax |
---|---|---|
expression |
side effects |
|
compound |
group statements |
|
empty |
do nothing |
|
labeled |
name a statement |
|
variable |
declare a variable |
|
|
conditional |
|
|
conditional |
|
|
loop |
|
|
loop |
|
|
simplified loop |
|
|
collection iteration |
Java 5.0 and later; also called “foreach” |
|
exit block |
|
|
restart loop |
|
|
end method |
|
|
critical section |
|
|
throw exception |
|
|
handle exception |
|
Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.