Every [programming language](https://www.upgrad.com/blog/top-programming-languages-to-learn/) uses loops to execute the same block of code iteratively. [Java](https://www.upgrad.com/blog/how-to-code-compile-and-run-java-projects/) has different types of loop statements, viz. for loop, while loop, do-while loop. Another kind of loop introduced in the Java 5.0 version is the for-each loop, also called enhanced for loop.

It uses the same keyword ‘for’ as in for loop to iterate in collecting items, such as an array. In a for-each loop, there is no need to initialize the loop counter variable. Instead, a variable is declared along with the array name. To get more understanding of its usage, check the syntax of the for-each loop in Java.

**Table of Contents**

*   [Syntax of For-Each Loop in Java](https://www.upgrad.com/blog/for-each-loop-in-java/#Syntax_of_For-Each_Loop_in_Java)
*   [How Does For-Each Loop Work?](https://www.upgrad.com/blog/for-each-loop-in-java/#How_Does_For-Each_Loop_Work)
*   [Examples of the For-Each Loop in Java](https://www.upgrad.com/blog/for-each-loop-in-java/#Examples_of_the_For-Each_Loop_in_Java)
*   [How is the For-Each Loop Different from For Loop?](https://www.upgrad.com/blog/for-each-loop-in-java/#How_is_the_For-Each_Loop_Different_from_For_Loop)
*   [Advantages of For-Each Loop in Java](https://www.upgrad.com/blog/for-each-loop-in-java/#Advantages_of_For-Each_Loop_in_Java)
*   [Disadvantages of For-Each Loop in Java](https://www.upgrad.com/blog/for-each-loop-in-java/#Disadvantages_of_For-Each_Loop_in_Java)
*   [Conclusion](https://www.upgrad.com/blog/for-each-loop-in-java/#Conclusion)

 

#Java 

For-Each Loop in Java [With Coding Examples]
2.75 GEEK