For each loop(enhanced for loop)

231 views.

This loop is introduced in java 1.5 version and it designed for accessing the elements the from arrays (collection). It is also called as enhanced for loop.

Syntax:

for(declaration: arrayName){

statements;

}

The declaration of a variable in for each loop must be same as that of the type of elements available in the array. In for each loop, the statements will be executed one time for each elements available in the array and therefore called for each loop.

Program:

 

 

 

Leave a Reply