do while loop in java

Previous
Next

do-while:

  • Check the condition after execution of a block and continue with execution depends on the validity of condition.
  • Block execute at least once though the condition is false for the first time.

Syntax:

do
{
	Logic….
} while (condition);

Flow-Chart:

While loop executes the block only when condition is valid:

class Test 
{
	public static void main(String[] args) 
	{
		int i=1;
		while(i>10)
		{
			System.out.println("Hello");
		}
	}
}

Do while loop executes the block once, even the condition fails:

class Test 
{
	public static void main(String[] args) 
	{
		int i=1;
		do
		{
			System.out.println("Hello");
		}while(i>10);
	}
}
Previous
Next

Add Comment

Courses Enquiry Form