Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Wiki Markup
As detailed in [§14.14.2, "The Enhanced For Statement" |http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.14.2]  of the _Java Language Specification_ \[[JLS 2005|AA. Bibliography#JLS 05]\]:

an enhanced for statement of the form

Code Block
for (ObjType obj : someIterableItem) { 
  // ...
}

is equivalent to a standard for loop of the form

Code Block
for (Iterator myIterator = someIterableItem.iterator(); iterator.hasNext();) {
  ObjType obj = myIterator.next();
  // ...
}

...

Declare all enhanced for statement loop variables to be final. The final declaration causes Java compilers to flag and reject any assignments made to the loop variable.

...

The attempt to skip to the next item appears to succeed because the assignment is successful , and the value of processMe is updated. Unlike an original for loop, however, the assignment leaves the overall iteration order of the loop unchanged. As a result, the object following the skipped object is processed twice.

...

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="53d26be7f3ca80fb-14443e89-4c82409f-bd40a827-3229189fd94411e9225ae6e9"><ac:plain-text-body><![CDATA[

[[JLS 2005

AA. Bibliography#JLS 05]]

[§14.14.2,"The enhanced for statement"

http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.14.2]

]]></ac:plain-text-body></ac:structured-macro>

...