For Loop in C++

Level 251 keystrokes

Uses a for loop that counts i from 1 to 5 and prints each value on its own line.

C++ code

// int i = 1 sets the start; i <= 5 is checked before each pass
// i++ adds 1 to i after each pass, so i takes the values 1 to 5
1for (int i = 1; i <= 5; i++) {
// Prints the current value of i followed by a newline
2 cout << i << endl;
3}

Output

1
2
3
4
5
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
  • ;× 3
  • +× 2
  • =× 2
  • (× 1
  • )× 1
  • {× 1
  • }× 1

More C++ examples at level 2

← C++ typing practice