CH8 – The Enhanced for Loop

  1. Create a new class named EnhancedLoop.
  2. Add the main method and the following code.
public class EnhancedLoop{
  public static void main(String[] args){
    int[] values = {1,22,33,44,23,98,87,34};
    for (int value : values){
      System.out.println(value);
    }
  }
}
  1. Compile and run the program.
$ javac EnhancedLoop.java
$ java EnhancedLoop
1
22
33
44
23
98
87
34

Refer to the following video by LearningLad if you need more information on using the For Each loop to iterate through an array.