Could someone please why do we say that the syntax of enhanced for loop (for-each) in java in streamlined.
Also, my java compiler does not compile programs containing the enhanced for loop. It gives errors like:

for(int x:collection) { }
^
; expected

Could someone suggest solutions to this?

what version of the compiler are you using?

can you post your entire code?

I am using Java2 SDK Standard Edition V1 3.0_02.
My code is a s follows:

class forEach
{
    public static void main(String args[])
    {
        int nums[]={1,2,3,4,5};
        int sum=0;
        for(int x:nums)
        {
            System.out.println("Value is:"+x);
            sum+=x;
        }
        System.out.println("Summation: "+sum);
    }
}

thought so.
The for-each structure wasn't introduced until the 1.5 version of the language.
Your compiler is about 6+ years too old.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.