Names specified here
Name Description Notes Source Availability
break Exit from loop or switch statement L Keyword C89 C90 C95 C99 C11

The keyword break forms a break statement, which follows the syntax of jump-statement:

jump-statement
break ;

It's used to exit unconditionally from loops:

for (int i = 0; i < 10; i++) {
  if (i == 5)
    break;
  printf("Line: %d\n", i);
}
Line: 0
Line: 1
Line: 2
Line: 3
Line: 4

…and to exit from a switch statement, so that execution of the selected statements doesn't fall through to the next label:

int i = 3;

switch (i) {
default:
  printf("Foo\n");
  break;

case 2:
  printf("Bar\n");
  break;

case 4:
  printf("Baz\n");
  break;
}
Foo

When a break statement occurs inside nested loops and switch statements, it applies to the innermost one. Future versions of C might support the syntax break identifier ;, allowing a jump out of any enclosing construct, not just the innermost one.


CHaR
Sitemap Supported
Site format updated 2024-06-05T22:37:07.391+0000
Data updated 1970-01-01T00:00:00.000+0000
Page updated 2022-06-17T21:43:05.000+0000