Java do while

What is Java do while Loops?

When we want to execute a block execute multiple time then we use loop.It executes until condition is true.

The do - while executes a block of code as long as a given condition is true.

do {
  // code block to be executed
}while (condition);

Sample program with do-while loop
Write a program or WAP to print 1 to 10 using do-while loop.

class SampleDoWhile
{
   public static void main(String args[])
   {
        int num= 1;
        do
        {
          System.out.println(num);
	  num++;
	}while (num <= 10);
	  
   }
}


Output:

1
2
3
4
5
6
7
8
9
10

java java tutorials learn java study java