The enhanced for
statement introduced in Java 5 (also known as the for-each idiom) is primarily used for iterating over collections of objects. Unlike the basic for
statement, assignments to the loop variable fail to affect the loop's iteration order over the underlying set of objects. Consequently, assignments to the loop variable can have an effect other than what is intended by the developer. This provides yet another reason to avoid assigning to the loop variable in a enhanced for
loop.
Wiki Markup |
---|
As detailed in the JLS, [§14.14.2, "The Enhanced For Statement" |http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.14.2] \[[JLS 2005|AA. References#JLS 05]\]: |
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="b614a0f89347d70d-a6208177-4ba64834-a80393ae-0c01777a390e124638773a91"><ac:plain-text-body><![CDATA[ | [[JLS 2005 | AA. References#JLS 05]] | [§14.14.2,The Enhanced | http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.14.2] | ]]></ac:plain-text-body></ac:structured-macro> |
...