Skip to content

JS Do-While Loop

Syntax

The do-while loop in JavaScript executes a block of code once, and then repeatedly executes it as long as the specified condition evaluates to true.

do {
// Code to execute
} while (condition);

Example

let count = 1;
do {
console.log(count);
count++;
} while (count <= 5);
// Output:
// 1
// 2
// 3
// 4
// 5