do..while Loop

do..while Loop

  • A do…while loop repeats until a specified condition evaluates to false
do {
  statement
} while (condition)
  • statement is always executed once before the condition is checked (and then again until the while condition returns false)

  • With do…while loops, everything in-between the curly braces (i.e. statement(s)) will run at least once

Example

let n = 0

do {
  console.log(n)
  n++
} while (n < 0)
  • the loop will run at least once and then terminate because 0 is NOT < 0

JS Bin on jsbin.com