0
What is an enhanced for loop?
3 ответов
+ 1
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);
}
by @Mojtaba
0
enchanted for loops ,we usually use it for arrays
for example
for(MyClass(type) myClass(name):MyClassArray(all classes in array))
{
myClass.writeInForLoop();//what do you want
}
0
if you want to use normal for loop you will use this
for(int i=0;i<MyClassArray.size();i++)
{
MyClass myClass=MyClassArray[i];
myClass.writeInForLoop();
}