Do While Loop in JavaScript

Level 253 keystrokes

A do-while loop executes at least once before checking the condition.

JavaScript code

// Declare and initialize variable i to 0
1let i = 0;
// do-while executes the block first, then checks condition
2do {
// Output current value of i
3 console.log(i);
// Increment i by 1
4 i++;
// Continue while i is less than 2
5} while (i < 2);

Output

0
1
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this JavaScript code and how often they appear.

  • ;× 4
  • (× 2
  • )× 2
  • +× 2
  • .× 1
  • {× 1
  • }× 1
  • <× 1
  • =× 1

More JavaScript examples at level 2

← JavaScript typing practice