[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/windweb/JavaTutorial/master/src/F030_ForEachLoop.java [Back]  [Original]

/* For Each Loop /  for-each
forEach -  ,      .
 :
forEach(_  : ) { ... }


*/

public class F030_ForEachLoop {
    public static void main(String[] args) {
        String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};

        //  1    for
/*    for  ,  
    
       */
        System.out.println("\n" + " for,   "+"\n");

        for (int i = 0; i < cars.length; i++) //   
            System.out.println(cars[i]);

        System.out.println("\n" +" for,   "+"\n");

        for (int i = cars.length - 1; i >= 0; i--) //   
            System.out.println(cars[i]);

        System.out.println("-------");
        System.out.println("\n" + " foreach,   "+"\n");
        //  2   foreach

        for (String currentCar : cars)  //    
            System.out.println(currentCar);

    }
}

Web Proxy Viewer  |  New URL  |  Original Page