MKF
0
Q:

java do while

do {
	// loop content
} while (/* condition */);
6
do {
  // code block to be executed
}
while (condition);
2
do
{
   statement(s);
} while(condition);
4
do while loop java executes the statements and then evaluates the 
expression/condition of loop’s body until given condition is true.
Here’s do while loop syntax in java.

// do while loop java
do{
   statement(s);
}while(expression/condition);
2
class DoWhileLoopExample {
    public static void main(String args[]){
         int i=10;
         do{
              System.out.println(i);
              i--;
         }while(i>1);
    }
}
1
10
9
8
7
6
5
4
3
2
1
class DoWhileLoopExample2 {
    public static void main(String args[]){
         int arr[]={2,11,45,9};
         //i starts with 0 as array index starts with 0
         int i=0;
         do{
              System.out.println(arr[i]);
              i++;
         }while(i<4);
    }
}
0
while True: #True can be replaced with a different condition
  #result
0

package com.journaldev.javadowhileloop;

public class JavaDoWhileLoop {

	public static void main(String[] args) {

		int i = 5;
		do {
			System.out.println(i);
			i++;
		} while (i <= 10);
	}
}
-2
do
{
  // do something
} while (true);
0

New to Communities?

Join the community