Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jdt-core-dev] New for loop


The enhanced for statement (foreach) is now supported. We still need to do more testing, but the implementation is in place.

We can successfully compile:

import java.util.ArrayList;

public class X {
        public static void main(String[] args) {
                ArrayList<Integer> arrayList = new ArrayList<Integer>();
                for (int i = 0; i < 10; i++) {
                        arrayList.add(new Integer(i));
                }
                int sum = 0;
                for (Integer e : arrayList) {
                        sum += e.intValue();
                }
                System.out.println(sum);
        }
}

The result is: 45

We can also compile:

public class X {
        public static void main(String[] args) {
                int[] tab = new int[] {1, 2, 3, 4, 5, 6, 7 , 8, 9};
                int sum = 0;
                for (int e : tab) {
                        sum += e;
                }
                System.out.println(sum);
        }
}

The result is still: 45

Olivier

Back to the top