For Loop Basics in C

Level 250 keystrokes

Uses a for loop that counts i from 1 to 5 and prints each value followed by a space: "1 2 3 4 5".

C code

// for (start; condition; step): i starts at 1, runs while i <= 5, i++ after each pass
// i is declared inside the for, so it exists only within the loop
1for (int i = 1; i <= 5; i++) {
// Prints the current i followed by a space
2 printf("%d ", i);
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.

  • ;× 3
  • "× 2
  • (× 2
  • )× 2
  • +× 2
  • =× 2
  • ,× 1
  • {× 1
  • }× 1
  • %× 1

More C examples at level 2

← C typing practice