Java Do While


Before testing the condition the body of the loop is necessary to execute in those situations, it can be handled by using do-while loop method in Java program. do statement which evaluates the body of the loop first and the condition will be checked by using the while statement at the end. In do while loop at least one time the body of the loop will be executed, even condition is true or false.

Syntax:-

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

Example:-

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



Onlinetpoint is optimized for basic learning, practice and more. Examples are well checked and working examples available on this website but we can't give assurity for 100% correctness of all the content. This site under copyright content belongs to Onlinetpoint. You agree to have read and accepted our terms of use, cookie and privacy policy.