While Loop in C

Level 251 keystrokes

Uses a while loop that prints i and adds 1 to it as long as i is less than 3, producing "0 1 2".

C code

// The loop counter starts at 0
1int i = 0;
// The condition is checked before each pass; the loop stops once i reaches 3
2while (i < 3) {
// Prints the current value followed by a space: 0, 1, then 2
3 printf("%d ", i);
// Moves i toward 3; without this line the loop would never end
4 i++;
5}

Output

0 1 2
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
  • ,× 1
  • {× 1
  • }× 1
  • %× 1
  • <× 1

More C examples at level 2

← C typing practice