For Loop Countdown in C++

Level 274 keystrokes

Counts down from 5 to 1 with a for loop that decrements i, then prints Go! after the loop.

C++ code

// i starts at 5, the loop runs while i >= 1, and i-- lowers i by 1 each pass
1for (int i = 5; i >= 1; i--) {
// Prints 5, 4, 3, 2 and 1, one per line
2 cout << i << endl;
3}
// Runs once after the loop ends (i is 0) and prints Go!
4cout << "Go!" << endl;

Output

5
4
3
2
1
Go!
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.

  • <× 8
  • ;× 4
  • -× 2
  • "× 2
  • =× 2
  • !× 1
  • (× 1
  • )× 1
  • {× 1
  • }× 1

More C++ examples at level 2

← C++ typing practice