Java - Loop Control-do while loop - Java

A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time.

Syntax

Following is the syntax of a do...while loop −

Notice that the Boolean expression appears at the end of the loop, so the statements in the loop execute once before the Boolean is tested.

If the Boolean expression is true, the control jumps back up to do statement, and the statements in the loop execute again. This process repeats until the Boolean expression is false.

Flow Diagram

java_do_while_loop

Example

This will produce the following result −

Output

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Java Topics