break & continue in C
break exits its nearest loop or switch immediately; continue skips the rest of the current iteration and starts the next. Together they express early exits and skips far more readably than flag variables — search loops break on found, filters continue on bad items.
Both affect only the innermost enclosing loop. Escaping outer loops needs a flag, a function return, or goto — which is exactly why goto survives in C for nested-loop exits and shared cleanup.
break exits now
Control jumps past the loop's closing brace the moment break executes — remaining iterations never happen.
continue skips ahead
continue abandons only the current pass: for loops still run their step expression, while loops jump to the test.
Only the innermost loop
In nested loops, both affect the closest loop — outer exits need flags, returns, or goto.
Prefer over flags
Direct break on found beats found-flag plumbing — fewer variables, clearer exits, less state to reason about.
#include <stdio.h> int main(void) { int v[] = {3, -1, 4, -2, 5}; int i; for (i = 0; i < 5; ++i) { if (v[i] < 0) continue; if (v[i] == 4) break; printf("%d ", v[i]); } printf("\n"); return 0;}Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in C yourself — building beats watching.