Java do while Loop

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

The do block is executed at least once, even if the condition is false.


//code to be executed   

}while (condition);  


Example :

import java.util.*;

public class Main {
public static void main(String[] args) {
int p=0;
System.out.println("The number is : "+p);

Output :

The number is : 0
The number is : 1
The number is : 2
The number is : 3
The number is : 4
The number is : 5
The number is : 6


Leave a Reply

Your email address will not be published. Required fields are marked *