Concept
How does Java use variables and collections in enhanced for loops?
ComputerScienceOne / Enhanced For Loops
"The code (int a : arr) should be read as “for each integer element a in the collection arr ...” Within the enhanced for loop, the variable a will be automatically updated for you on each iteration. Outside the loop body, the variable a is out-of-scope. Java allows you to use an enhanced for loop with any array or collection (technically, anything that implements the Iterable interface). One example is a List , an ordered collection of elements. Code Sample 28.6 contains an example."
Related Ideas
- How do do-while loops differ from while loops in Java?ComputerScienceOne · For Loops
- How do nested loops execute in Java?ComputerScienceOne · Nested Loops
- How are for loops structured and scoped in Java?ComputerScienceOne · Do-While Loops
- What topics are covered in the loops section?ComputerScienceOne · Nested Loops
- How do do-while loops differ from while loops in C?ComputerScienceOne · For Loops