Do While Loops In Java

Aditya DeshwalAditya Deshwal
1 min read

Do while loop is a unique way to write the while loop code the syntax of Do While loop is kind of unique.

Syntax

do{
// Statement 
}while(conditionState);

So, what is this "do"? why we are writing this? because whenever we write code in the do. Then it will execute and then it will check the condition. Unlike in a while loop where we check the condition state the execute the code inside it.

Example 1:

Write a code to print 10 Times Hello World.

public class DoWhile {
    public static void main(String[] args) {
        int i = 1;
        do {
            System.out.println(i+" Hello World");
            i++;
        }while(i<=10);
    }

}
0
Subscribe to my newsletter

Read articles from Aditya Deshwal directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Aditya Deshwal
Aditya Deshwal