1const fruits = ['mango', 'papaya', 'pineapple', 'apple'];
2
3// Iterate over fruits below
4
5// Normal way
6fruits.forEach(function(fruit){
7 console.log('I want to eat a ' + fruit)
8});
1int [] intArray = { 10, 20, 30, 40, 50 };
2
3for( int value : intArray ) {
4 System.out.println( value );
5}
1//itemset contains variables of type <Data Type>
2for(<Data Type> item : itemset) {
3 //loop
4}
1public class ForEachLoopExample
2{
3 public static void main(String[] args)
4 {
5 int[] numbers = {2, 4, 6, 8, 10};
6 // for each loop
7 for(int n : numbers)
8 {
9 System.out.println(n);
10 }
11 }
12}
1public class JavaArray {
2
3 public static void main(String[] s) {
4 int[] age = new int[5];
5 age[0] = 21;
6 age[1] = 23;
7 age[2] = 45;
8 age[3] = 31;
9 age[4] = 33;
10 for (int a : age) {
11 System.out.println("age= " + a);
12 }
13
14 }
15}
16