Do While Loop Java

Sharing is healthy !!

Hey guys!! Welcome to flower brackets blog. In this post you will learn do while loop java.

Do While LOOP java

Do while loop in java , is a statement that assess its expression at the bottom of the loop rather of the top. Here’s syntax and example of do while loop in java,

Syntax:
do
{
   statement(s);
}
while(expression);

Also Read – Java If Else

Flow Diagram

Do While Loop Java

Example:
public class DoWhile
{
   public static void main(String[] args)
   {
      int x = 0;
      do
      {
         System.out.println("x value is: " + x);
         x++;
      }
      while(x < 6);
   }
}

Output:

x value is: 0
x value is: 1
x value is: 2
x value is: 3
x value is: 4
x value is: 5


do while loop iterate – arrays

Let’s see an example of do while loop in java using arrays. Here’s the code,

public class DoWhileExample
{
   public static void main(String[] args)
   {
      int arrayExample[] = {05,14,10,50};
      int a = 0;
      System.out.println("Do while loop example java : ");
      do
      {
         System.out.println(arrayExample[a]);
         a++;
      }while(a < 4);
   }
}

Output:

Do while loop example java :
5
14
10
50


conclusion

That’s it guys. This is all about do while loop in java. I hope you have understood the concept.

You can subscribe to my blog flower brackets if you you haven’t already.

Do share this post if you like.

Sharing is healthy !!