Java Reference
In-Depth Information
Table 2-5. Java statements
Statement
Purpose
Syntax
expression
side efects
var = expr ; expr ++; method (); new Type ( );
a x
compound
group statements
{ statements }
empty
do nothing
;
labeled
name a statement
label : statement
variable
declare a variable
[final] type name [= value ] [ , name [= value ]] …;
conditional
if ( expr ) statement [ else statement ]
if
conditional
switch ( expr ) { [ case expr : statements ] …
[ default : statements ] }
switch
loop
while ( expr ) statement
while
loop
do statement while ( expr );
do
simpliied loop
for ( init ; test ; increment ) statement
for
foreach
collection iteration for ( variable : iterable ) statement
exit block
break [ label ] ;
break
restart loop
continue [ label ] ;
continue
end method
return [ expr ] ;
return
critical section
synchronized ( expr ) { statements }
synchronized
throw exception
throw expr ;
throw
handle exception
try { statements } [ catch ( type name ) { state
ments } ] .. . [ finally { statements } ]
try
verify invariant
assert invariant [ : error ];
assert
Expression Statements
As we saw earlier in the chapter, certain types of Java expressions have side effects.
In other words, they do not simply evaluate to some value; they also change the
 
Search WWH ::




Custom Search