Start Coding Now

Do-While Loop in Java - Syntax and Examples

Understand the do-while loop in Java. Guaranteed to execute the code block at least once.

Do-While Loop

Similar to the while loop, but it executes the code block once before checking the condition.

do {
    // code block
}
while (condition);

Example

int i = 0;
do {
  System.out.println(i);
  i++;
}
while (i < 5);

Even if the condition is false initially, the code block runs once.

Frequently Asked Questions