The for-each loop was introduced in Java 5. Actually, the loop is a
for loop with a
: placed between a variable and a data structure such as an array. Each item of the data structure is stored in the variable per loop iteration. The loop terminates when the final item has been processed. To understand how to write for-each loops in Java, follow these four steps.
namesarray in the
namevariable for each iteration of the loop.