+ 2

What is difference between Normal For loop and Enhanced For Loop ?

9th Jul 2016, 9:26 AM
Vinod Luhar
9 Antworten
+ 7
This means you have to use a regular For loop for getting each object in the array so it takes time to give an index and get each object one by one. But with enhanced type it will use each object in array by itself and you don't need to define it. e.g. int[] arr={1,2,3}; for (x=0;x <arr.length;x++) { System.out.println(arr[x]); } instead int[] arr={1,2,3}; for (int t: arr) { System.out.println(t); }
19th Jul 2016, 2:59 PM
Mojtaba
Mojtaba - avatar
+ 2
it took less memory in stack,i.e less frames will be there in stack,efficiency of the code will be high|
12th Dec 2016, 7:46 PM
anmol gupta
anmol gupta - avatar
+ 1
enhanced for loop helps in easily accessing each members in an array
9th Jul 2016, 9:49 AM
sreeraj g
sreeraj g - avatar
0
Is it different than for each loop?
9th Jul 2016, 10:04 AM
Vinod Luhar
0
in enhanced for loop ,"we access all the elements of array" and for this purpose only this enhanced for loop is used. we can do above work by using normal for loop also.but coding is simple for enhanced for loop... if u want to give some conditions,then u cant use enhanced for loop instead we use normal for loop...
10th Jul 2016, 3:58 PM
Anup Shetty
0
the enhanced loop will save your time to code.
15th Sep 2016, 11:31 AM
Welly Wei
Welly Wei - avatar
0
its like for each loop im vb
21st Dec 2016, 2:09 PM
Abu Bakar Baig
Abu Bakar Baig - avatar
0
or you can say it checks each item in a collection... like checking the controls in form.controls for each control in me.controls here goes some code next
21st Dec 2016, 2:14 PM
Abu Bakar Baig
Abu Bakar Baig - avatar
- 4
both are same
9th Jul 2016, 10:28 AM
sreeraj g
sreeraj g - avatar