Java do while Loop Example

Java do-while Loop Example demonstrates how to use do-while in Java with an example.

do-while Loop Syntax

do {
// body of a loop
} while (condition);
Each iteration of the do-while loop first executes the body of the loop and then evaluates the conditional expression. If this expression is true, the loop will repeat. Otherwise, the loop terminates. As with all of Java’s loops, a condition must be a Boolean expression.

Simple do-while Loop Example

package net.javaguides.corejava.controlstatements.loops;

public class DoWhileLoopExample {
    public static void main(String args[]) {
        int n = 10;
        do {
            System.out.println("tick " + n);
        } while (n > 0);
tick 10
tick 9
tick 8
tick 7
tick 6
tick 5
tick 4
tick 3
tick 2
tick 1

Free Spring Boot Tutorial - 5 Hours Full Course

Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course