For Each loop In Java

 

The for each loop is also known as advanced or enhanced for loop and it is introduced in Java5. There are many benefits of for-each loop like better code readability and it is more convenient and concise.


class ForEach
{
public static void main(String args[])
{
int a[][]={{1,3},{3,4}};
for(int b[]:a)
{
for(int c:b)
{
System.out.println(c +" ");
}
Output:
1
3
3
4
 

 

Leave a Reply