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 |
|
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access