# Do While loop

A do-while loop is used to repeatedly execute a set of statements until the condition that it uses evaluates to false.

&#x20;**This loop checks the condition after it completes the execution of all the statements in its loop body.**

![](/files/-LTWTFWhO_n8hqwlokiF)

![](/files/-LTWTWDDoqpA0wHRMG_l)

#### Example 1: Program to print line 10 times

```java
package com.test.test1;

public class DoWhileEx {
	public static void main(String[] args) {
		int x = 1;
		do {
			System.out.println("Line : "+x);
			x++;
		} while (x <= 10);
	}

}
```

```
Line : 1
Line : 2
Line : 3
Line : 4
Line : 5
Line : 6
Line : 7
Line : 8
Line : 9
Line : 10
```

#### While Vs Do-while loop :

![](/files/-LTWXI5__QSQNgGV1IIK)

#### Problems:

Try all the examples as well as problems with while loop which are mentioned in [for loop](/core-java/flow-control/for-loop.md) section.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gyansetu-java.gitbook.io/core-java/flow-control/do-while-loop.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
