previous
|
start
|
next
Syntax 8.3: The "for each" Loop
for (
Type variable
:
collection
)
statement
Example:
for (double e : data)
sum = sum + e;
Purpose:
To execute a loop for each element in the collection. In each iteration, the variable is assigned the next element of the collection. Then the statement is executed.
previous
|
start
|
next