Do While Loop

 Do While Loop – In Java



package practice;

public class DoWhileLoop {

    public static void main(String[] args) {

        int i = 0;

        do {

            i = i + 1;
            System.out.println(i);

        } while (i < 5);

        // System.out.println(i);

    }

}

Explanation

This is a do-while loop, so the code inside the loop runs first, and then the condition i < 5 is checked after each iteration.

Output –

1
2
3
4
5