While Loop in C

Level 384 keystrokes

Uses a while loop to count down from 5 to 1, then prints Go!

C code

// Starting value of the countdown
1int count = 5;
// The condition is checked before each pass; the loop stops when count reaches 0
2while (count > 0) {
// Print the current value and a space
3 printf("%d ", count);
// Subtract 1; without this the loop would never end
4 count--;
5}
// Runs once after the loop, completing the line: 5 4 3 2 1 Go!
6printf("Go!\n");

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.

  • ;× 4
  • "× 4
  • (× 3
  • )× 3
  • -× 2
  • ,× 1
  • !× 1
  • {× 1
  • }× 1
  • \× 1

More C examples at level 3

← C typing practice