Java do-while loop
Do-while loop:
Do- while loop is similar to a while loop except for the fact that it is guaranteed to execute at least once.
Use a do-while loop when the exact number of iterations is unknown, but you need to execute a code block at least once.
After executing a part of a program for once, the rest of the code gets executed on the basis of a given boolean condition.
Syntax :
/* do {
//code
} while (condition); //Note this semicolon */
Example :
int i=1;
do{
System.out.println(i);
i++;
}while(i<=10);
Difference Between while loop and do-while loop :
Flow control of do-while loop :

Example
package com.company;
public class cwh_22_ch4_do_while {
public static void main(String[] args) {
int b = 10;
do {
System.out.println(b);
b++;
}while(b<5);
int c = 1;
do{
System.out.println(c);
c++;
}while(c<=45);
}
}
Output
10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45