3. Looping (Iterative) Structures

3.3. Syntax:

while (condition) {

    // Code

}

Example:

public class WhileLoopExample {

    public static void main(String[] args) {

        int i = 1;

        while (i <= 5) {

            System.out.println("Count: " + i);

            i++;

        }

        // Output:

        // Count: 1

        // Count: 2

        // Count: 3

        // Count: 4

        // Count: 5

    }

}

Notes:

Condition is checked before each iteration.

Risk of infinite loops if the condition never becomes false.