Java Reference
In-Depth Information
The output from the program is shown here:
As this output shows, the for-each style
for
automatically cycles through an array in se-
quence from the lowest index to the highest.
Although the for-each
for
loop iterates until all elements in an array have been examined,
it is possible to terminate the loop early by using a
break
statement. For example, this loop
sums only the first five elements of
nums
: