Curriculum
Course: Java Basic
Login

Curriculum

Java Basic

Java Home

0/1

Java Introduction

0/1

Java Get Started

0/1

Java Syntax

0/1

Java Comments

0/1

Java Type Casting

0/1

Java Operators

0/1

Java Booleans

0/1

Java Switch

0/1

Java Break / Continue

0/1

Java Errors and Exception

0/1
Text lesson

do

Example

The ensuing loop is guaranteed to execute at least once, irrespective of the condition’s truth value, as the code block executes before condition evaluation.

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

Definition and Usage

The “do” keyword, when paired with “while”, constructs a do-while loop.

The while loop iterates through a block of code as long as a specific condition remains true.

The do-while loop, a variant of the while loop, executes the code block initially and subsequently repeats the loop as long as the condition remains true.

Reminder: Ensure to increment the variable utilized in the condition, otherwise, the loop will perpetually continue.