Enhanced Loop

Enhanced loop in java programming.

Enhanced loop is supported in java from 1.5 versions and has simplified the way for loop had been used in java. Unlike traditional java loop where the initializations and declarations happens couple of time, enhanced loop is easy to use and avoids many declarations and initializations.

Take a look at the following example:

Class EnhancedLoop

{

            public static void main(String args[])

            {

                        String a[]={”abc”,”xyz”};

                        For(String x: a)

                        {

                                    System.out.println(x);

                        }

            }

}

As show here, in enhanced for loop “a” is the array reference assigned to string x on the left side and every time the loop executes each member of a is assigned to x in order.

2 Responses

09.10.05

good

09.10.05

I’m afraid I’m not all that computer savvy, but this is a good article.

Leave Your Response