Learn JavaScript
  • Introduction
  • Basics
    • Comments
    • Variables
    • Types
    • Equality
  • Numbers
    • Creation
    • Basic Operators
    • Advanced Operators
  • Strings
    • Creation
    • Concatenation
    • Length
  • Conditional Logic
    • If
    • Else
    • Comparators
    • Concatenate
  • Arrays
    • Indices
    • Length
  • Loops
    • For
    • While
    • Do...While
  • Functions
    • Declare
    • Higher order
  • Objects
    • Creation
    • Properties
    • Mutable
    • Reference
    • Prototype
    • Delete
    • Enumeration
    • Global footprint
Powered by GitBook
On this page
  1. Loops

Do...While

The do...while statement creates a loop that executes a specified statement until the test condition evaluates to be false. The condition is evaluated after executing the statement. Syntax for do... while is

do {
  // statement
} while (expression);

Lets for example see how to print numbers less than 10 using do...while loop:

var i = 0;
do {
  document.write(i + " ");
  i++; // incrementing i by 1
} while (i < 10);

Note: i = i + 1 can be written i++.

PreviousWhileNextFunctions

Last updated 4 years ago