Do-While Doubling in C++

Level 260 keystrokes

Uses a do-while loop to print x and double it while it stays below 50, so 5, 10, 20 and 40 are printed.

C++ code

// Initializes x with 5
1int x = 5;
// The body runs first; the condition is checked only after it
2do {
// Prints the current value of x
3 cout << x << endl;
// x *= 2 doubles x: 5, 10, 20, 40, 80
4 x *= 2;
// Repeats while x < 50; it stops at 80, so 80 is never printed
5} while (x < 50);

Output

5
10
20
40
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 C++ code and how often they appear.

  • <× 5
  • ;× 4
  • =× 2
  • (× 1
  • )× 1
  • {× 1
  • }× 1
  • *× 1

More C++ examples at level 2

← C++ typing practice