`break` — C Keyword
`break` — C Keyword
The break keyword in C: exits the nearest enclosing loop or switch statement.
`break` — C Keyword
The break keyword in C: exits the nearest enclosing loop or switch statement.
Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.
break (C)Exits the nearest enclosing for, while, do/while, or switch statement immediately.
break;
#include <stdio.h>
int main(void) {
/* Find first negative value */
int arr[] = {5, 3, -1, 7, -2};
int n = (int)(sizeof arr / sizeof arr[0]);
for (int i = 0; i < n; ++i) {
if (arr[i] < 0) {
printf("first negative at index %d\n", i); /* 2 */
break;
}
}
return 0;
}
break only exits the innermost enclosing loop or switch.breakint main() {
// Pick one facility from this reference page.
// Write the smallest program that exercises its main precondition,
// complexity rule, or lifetime constraint before scaling up.
return 0;
}