Java do-while Loop

A do while loop is similar to while loop, except that it guarantees to execute the block at once. Here the condition is checked after the execution of the block. If the expression is evaluated to true then only the block will execute otherwise it terminates the loop.

Java do while loop | do while loop example java

Syntax:

do {
     // statements
} while (expression);

public class demodowhile{

	public static void main(String[] args) {

		int d = 10;
		do {
			System.out.println(d);
			d++;
		} while (d <= 25);
	}
}
Example Output

Java Infinitive do-while Loop

Note: ctrl+c to exit from the program

Syntax:

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

public class demoInfinitive {  
public static void main(String[] args) {  
    do{  
        System.out.println("Java Point Tutorial");  
    }while(true);  
}  
}
Example Output

Share