advance for loop code example
Example 1: enhanced for loop java
class AssignmentOperator {
public static void main(String[] args) {
char[] vowels = {'a', 'e', 'i', 'o', 'u'};
for (char item: vowels) {
System.out.println(item);
}
}
}
Example 2: for each java
public class ForEachLoopExample
{
public static void main(String[] args)
{
int[] numbers = {2, 4, 6, 8, 10};
for(int n : numbers)
{
System.out.println(n);
}
}
}
Example 3: enhanced for loop java
for(int name: array)
{
System.out.print(name + " ");
}