Do While Loop In Java Example
Chapter:
Control Statements
Last Updated:
10-06-2016 12:20:30 UTC
Program:
/* ............... START ............... */
public class JavaDoWhile {
public static void main(String args[]) {
int x = 10;
do {
System.out.print("value of x : " + x);
x++;
System.out.print("\n");
} while (x < 20);
}
}
/* ............... END ............... */
Output
value of x : 10
value of x : 11
value of x : 12
value of x : 13
value of x : 14
value of x : 15
value of x : 16
value of x : 17
value of x : 18
value of x : 19
Notes:
-
do-while guarantees at least one execution of block of statements because loop evaluates the boolean expression at the end of the loop’s body.
- do while loop is similar to a while loop, except that a do while loop is guaranteed to execute at least one time.
Tags
Do While Loop, Java