Code Editor
Learn
Data Structures

For Each Loop

Since most for loops are very similar, Java provides a shortcut to reduce the amount of code required to write the loop called the for each loop.

Here is an example of the concise for each loop:

for (Integer grade : quizGrades){ System.out.println(grade); }

In the example above, the colon (:) can be read as "in". The for each loop altogether can be read as "for each Integer element (called grade) in quizGrades, print out the value of grade."

The loop will print out the value of each Integer element in quizGrades.

Note: the for each loop does not require a counter.

Report a Bug
If you see a bug or any other issue with this page, please report it here.