Languages
[Edit]
EN

JavaScript - do...while statement

0 points
Created by:
Adnaan-Robin
724

In this article, we would like to show you how to use the do...while statement in JavaScript.

Syntax

do {
  // statement
} while (condition);

Description

The do...while statement is used to create a loop that executes a specified block of code at least once, and then repeatedly executes the block until the test condition evaluates to false.

Practical example

In this example, the do...while loop iterates at least once and reiterates until i is no longer less than 3.

// ONLINE-RUNNER:browser;

let i = 0;

do {
  ++i;
  console.log(i);
} while (i < 3);

Output:

1
2
3

References

  1. do...while - JavaScript | MDN

Alternative titles

  1. JavaScript - do while loop
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

JavaScript - Statements & declarations

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join