What is the difference between break and continue in C?
#include <stdio.h>
int main(void) {
for (int i = 1; i <= 5; i++) {
if (i == 2) continue; // skip 2
if (i == 4) break; // stop at 4
printf("%d ", i);
}
printf("\n");
return 0;
}
Output:
Output of the above program is
1 3
continue skipped 2, and break ended the loop at 4. See break and continue.
Learn more about the similar topics:
| Tutorials |
|---|
| C If Else Statement |
| C Else If Ladder and Nested If |
| C Switch Statement |
| C While Loop |
| C Do While Loop |
| C For Loop |
| C Nested Loops |