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

Similar Programs Chapter Last Updated
Java For Loop And ForEach Loop Example Control Statements 03-09-2016
Java Enum And Switch Statement Control Statements 03-09-2016
Control Statements In Java Example Control Statements 19-06-2016
If Statement In Java Example Control Statements 17-06-2016
Java Switch Example Control Statements 14-06-2016
While Loop In Java Example Control Statements 08-06-2017
Return Statement In Java example Control Statements 15-07-2016
Print Stars In Java Example Control Statements 15-07-2016
Nested Loop In Java Example Control Statements 15-07-2016
Infinite While Loop In Java Control Statements 10-06-2016
Infinite Loop In Java Example Control Statements 15-07-2016
If Else Statement In Java Example Control Statements 10-06-2016
For Loop In Java Example Control Statements 07-06-2017
For Each In Java Example Control Statements 07-06-2017
Continue Statement In Java Example Control Statements 30-03-2017
Java Break Statement Example Control Statements 06-07-2016

1