# 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.**

![](https://3494582050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LSemf7mp1liQa7nfIAC%2F-LTWSc1ZBVW4hh8piuRG%2F-LTWTFWhO_n8hqwlokiF%2Fimage.png?alt=media\&token=6b2208e1-5e4f-41b4-97f3-440f4081f94d)

![](https://3494582050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LSemf7mp1liQa7nfIAC%2F-LTWSc1ZBVW4hh8piuRG%2F-LTWTWDDoqpA0wHRMG_l%2Fimage.png?alt=media\&token=2fae0a7c-8ecd-4bfd-92ac-22600100e3f6)

#### 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 :

![](https://3494582050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LSemf7mp1liQa7nfIAC%2F-LTWW-ix8zXFgnv7-DjX%2F-LTWXI5__QSQNgGV1IIK%2Fimage.png?alt=media\&token=a105bd21-fb44-448c-b83e-f994a39d8b82)

#### Problems:

Try all the examples as well as problems with while loop which are mentioned in [for loop](for-loop) section.
