Advertisement

break & continue

C Language Control Flow 📅 May 2026 ⏱ 1 min read 🆓 Free

break and continue Statements

breakexits the loop immediately (stops the loop).
continueskips the rest of the current iteration and goes to next.

break Statement — Exit Loop Early

c
#include <stdio.h>

int main() {
    // break: stop when we find first even number
    int i;
    printf("Finding first even: ");
    for (i = 1; i <= 10; i++) {
        if (i % 2 == 0) {
            printf("%d (found!)\n", i);
            break;  // EXIT the loop immediately
        }
    }
    
    // break in while: stop at number 5
    printf("Until 5: ");
    i = 1;
    while (1) {       // seemingly infinite loop
        printf("%d ", i);
        if (i == 5) break;  // exit when i reaches 5
        i++;
    }
    printf("\n");
    
    return 0;
}
▶ Output
Finding first even: 2 (found!)
Until 5: 1 2 3 4 5

continue Statement — Skip Current Iteration

c
#include <stdio.h>

int main() {
    // continue: skip odd numbers, print only even
    printf("Even numbers 1-10: ");
    for (int i = 1; i <= 10; i++) {
        if (i % 2 != 0) continue;  // skip odd, go to next i
        printf("%d ", i);          // only even numbers reach here
    }
    printf("\n");
    
    // continue: skip multiples of 3
    printf("Skip 3s (1-15): ");
    for (int i = 1; i <= 15; i++) {
        if (i % 3 == 0) continue;  // skip 3, 6, 9, 12, 15
        printf("%d ", i);
    }
    printf("\n");
    
    return 0;
}
▶ Output
Even numbers 1-10: 2 4 6 8 10 
Skip 3s (1-15): 1 2 4 5 7 8 10 11 13 14
StatementEffectWhere Used
breakImmediately exits loop or switchfor, while, do-while, switch
continueSkips remaining body, goes to next iterationfor, while, do-while only
Advertisement
← Back to C Language Index