The do-while Loop in Java


do-while loops are similar to while loops but guarantee the loop body will execute at least once.

Source Code

public class DoWhileLoopExample {
    public static void main(String[] args) {
        int i = 1;
        do {
            System.out.println("Value of i: " + i);
            i++;
        } while (i <= 5);
    }
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments