Showing posts with label for each loop. Show all posts
Showing posts with label for each loop. Show all posts

Java- for each loop / Chapter -6 / Flow Control (1.5v)


java for each loop

java for each loop came into 1.5 version.


It is the specially designed loop to retrieve elements of arrays and collections.


example 1 :-
Q. print elements of the one-dimensional array?
int [ ] a={1,2,3,4,5};
To prints the elements of the array, we have 2 approaches.

1.old approach (old for loop) :-

for(int i=0 ; i<a.lenght ;i++ )
{
System.out.ptintln(a[i]);
}                                                   Output is  :
1
2
3
4
5

2. new approach (for each loop):-

for(int a1 :a )
{
System.out.ptintln(a1);
}

Output is :

Java- for each loop / Chapter -6 / Flow Control (1.5v)

javabychetan.blogspot.com
for each loop came into 1.5 version.It is specially designed loop to retrieve elements of arrays and collections.
example 1 :-
Q. print elements of the one-dimensional array?
 int [ ] a={1,2,3,4,5};
 To prints the elements of the array, we have 2 approaches.

1.old approach (old for loop) :-

for(int i=0 ; i<a.lenght ;i++ )              
{                                                      
System.out.ptintln(a[i]);
  }                                                   Output is  :
                                                                1            
                                                                2
                                                                3
                                                                4
                                                                5

2. new approach (for each loop):-

for(int a1 :a )
 {
System.out.ptintln(a1);                              
}      

Output is :  

Flipkart End Of Season Sale






© Copyright 2017 Javabychetan.blogspot.com