0% found this document useful (0 votes)
3 views1 page

Java Enhanced For Loop Explained

Java scripts 7

Uploaded by

siva
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Java Enhanced For Loop Explained

Java scripts 7

Uploaded by

siva
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

For each looplenhanced for loop): This loop is introduced in java 1.

5 version and it designed


for accessing the elements from arrays(collection). It is also called as enhanced for loop.
Syntax:
for(declaration : arrayName)
statements;

The declaration of avariable 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 element
available in the array and therefore called for each loop.

Program 13:
class ArrayDemo {
public staticvoid main(Stringl] args) {
int[] arr;
arr =new int[5];
[Link](arr[0]);
[Link](arr[1);
[Link](arr[2]);
[Link](arr[3));
[Link](arr[4);
arr[0] = 11;
arr[1]=22;
arr[2]=33;
arr[3] =44;
arr[4] = 55;
for(int i-0; [Link] ;it+) {
[Link](arr[i)):

for(int x: arr) {
[Link](x)

You might also like