While Loop with Break in C++
Level 270 keystrokes
Starts an endless while (true) loop that prints n and leaves it with break once n reaches 3, so 1, 2 and 3 are printed.
C++ code
// Initializes the counter n with 11int n = 1;// The condition is always true, so only break can end this loop2while (true) { // Prints the current value of n3 cout << n << endl; // After 3 has been printed, break leaves the loop4 if (n == 3) break; // Otherwise increases n by 1 and repeats5 n++;6}Output
1 2 3
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.
;× 4<× 4=× 3(× 2)× 2+× 2{× 1}× 1