Categories
java

do while in java with example

do while in java with example

In this tutorial, we will learn do while in java with example

do while is little bit different from other looping statements, because other looping statements while execute only when condition satisfy

But do while will execute without condition once, after that it will check condition to execute next statement

Syntax

do{  
//code
}while(condition);  

Example

public class DoWhileExample {
	  
	public static void main(String[] args) {
       int i = 1;
       do {
          System.out.println("Loop Count " + i);
          i++;
      } while (i <= 5);
   }
}

Output

Loop Count 1
Loop Count 2
Loop Count 3
Loop Count 4
Loop Count 5
Download

https://github.com/rkumar9090/BeginnersBug/blob/master/BegineersBug/src/com/geeks/example/DoWhileExample.java

Related Articles

https://beginnersbug.com/while-loop-using-boolean-datatype-in-java/