Java Reference
In-Depth Information
2. Second, another for iteration step is performed.
♦ If the for statement does not have label L , the for statement completes abruptly
because of a continue with label L .
• If execution of the Statement completes abruptly for any other reason, the for state-
ment completes abruptly for the same reason.
Note that the case of abrupt completion because of a break with a label is handled by
the general rule for labeled statements (§ 14.7 ) .
14.14.2. The enhanced for statement
The enhanced for statement has the form:
EnhancedForStatement:
for ( FormalParameter : Expression ) Statement
The following is repeated from § 8.4.1 and § 8.3 to make the presentation here clearer:
FormalParameter:
VariableModifiers opt Type VariableDeclaratorId
VariableDeclaratorId:
Identifier
VariableDeclaratorId []
The type of the Expression must be Iterable or an array type (§ 10.1 ) , or a compile-time error
occurs.
The scope and shadowing of a local variable declared in the FormalParameter part of an
enhanced for statement is specified in § 6.3 and § 6.4 .
The meaning of the enhanced for statement is given by translation into a basic for statement,
as follows:
• If the type of Expression is a subtype of Iterable , then the translation is as follows.
If the type of Expression is a subtype of Iterable < X > for some type argument X , then
let I be the type java.util.Iterator < X >; otherwise, let I be the raw type java.util.Iterator .
The enhanced for statement is equivalent to a basic for statement of the form:
Click here to view code image
for ( I #i = Expression .iterator(); #i.hasNext(); ) {
VariableModifiers opt TargetType Identifier =
Search WWH ::




Custom Search