Break Statement in C

Level 388 keystrokes

Uses break to exit a loop early when i reaches 5.

C code

// Written to run up to 10, but break stops it earlier
1for (int i = 1; i <= 10; i++) {
// When i reaches 5…
2 if (i == 5) {
// …leave the loop at once; the printf below is skipped for 5
3 break;
4 }
// Runs only for i = 1 to 4
5 printf("%d ", i);
6}
// Execution continues here after break: the output is 1 2 3 4
7printf("\n");

Output

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

More C examples at level 3

← C typing practice