3. Looping (Iterative) Structures

3.2. Example:

public class EnhancedForLoopExample {

    public static void main(String[] args) {

        int[] numbers = {1, 2, 3, 4, 5};

        for (int num : numbers) {

            System.out.println("Number: " + num);

        }

        // Output:

        // Number: 1

        // Number: 2

        // Number: 3

        // Number: 4

        // Number: 5

    }

}

Notes:

· Simplifies iteration over arrays or Iterable objects.

· Cannot modify the collection’s structure during iteration.

while Loop

Repeats a block of code as long as a condition is true.