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 51int x = 5;// The body runs first; the condition is checked only after it2do { // Prints the current value of x3 cout << x << endl; // x *= 2 doubles x: 5, 10, 20, 40, 804 x *= 2;// Repeats while x < 50; it stops at 80, so 80 is never printed5} while (x < 50);Output
5 10 20 40
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