0Pricing
Java Academy · Lesson

Do-While & When to Use It

Run the loop body at least once with do-while. Learn syntax, use-cases, differences from while, and common pitfalls.

Do-While Concept

do-while runs the body before checking the condition. So it runs at least once.

Syntax

Syntax

int i = 0;
do {
// work
i = i + 1;
} while (i < 3);

The semicolon after while (...) is required.

All lessons in this course

  1. While Loop Basics
  2. Do-While & When to Use It
← Back to Java Academy