Java Do-While-Loop

Oct 24, 2024 9:24 AM

Bei Do-While-Loop wird die Anweisung mindestens 1 mal wiederholt.
Es folgt die Denkweise von While-Loop

public class Main {
    public static void main(String[] args) {
        boolean condition = true;
        int counter = 0;

        do {
            System.out.println("Die Schleife läuft: " + counter);
            counter++;
            if (counter >= 5) {
                condition = false; // Schleife beenden, wenn counter >= 5
            }
        } while (condition);
    }
}