+ 2
What is difference between Normal For loop and Enhanced For Loop ?
9 ответов
+ 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); }
+ 2
it took less memory in stack,i.e less frames will be there in stack,efficiency of the code will be high|
+ 1
enhanced for loop helps in easily accessing each members in an array
0
Is it different than for each loop?
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...
0
the enhanced loop will save your time to code.
0
its like for each loop im vb
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
- 4
both are same