Javatpoint Logo

91-9990449935

 0120-4256464

Java do-while Loop

The Java do-while loop is used to iterate a part of the program several times. If the number of iteration is not fixed and you must have to execute the loop at least once, it is recommended to use while loop.

It is executed at least once because condition is checked after loop body.

Syntax:

flowchart of do while loop in java

Example:

Output:

1
2
3
4
5
6
7
8
9
10

Java Infinitive do-while Loop

If you pass true in the do-while loop, it will be infinitive do-while loop.

Syntax:

Example:

Output:

infinitive do while loop
infinitive do while loop
infinitive do while loop
ctrl+c

Now, you need to press ctrl+c to exit from the program.