Fringetos
0
Q:

do while java

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
while(i < 5) //while i < 5 stay in the loop
{
  System.out.print(i);
  i++;
}
/*
	do someting
	change variable
    call methods
    etc...
*/
1
class DoWhileLoopExample {
    public static void main(String args[]){
         int i=10;
         do{
              System.out.println(i);
              i--;
         }while(i>1);
    }
}
1
do
{
	...
} while(condition);
0
10
9
8
7
6
5
4
3
2
1
while(/*condition*/){
 //action 
}

do{
 //action  
}while(/*condition*/);

for(int i = 0; /*condition*/; i++){
  
}

String[] array = new String[]{"1","2","3"};
for(String value:array){
  //action
}
0
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

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

New to Communities?

Join the community