Skip to main content

Break versus continue

Short answer

break terminates the loop entirely, transferring control after the loop; continue skips the rest of the current iteration and proceeds to the next. Example: break in a loop for i=1..10 when i==5 yields 1 2 3 4; continue skips just 5, yielding 1 2 3 4 6 7 8 9 10.

Distinguish between break and continue statement with example.

breakcontinue
Terminates the loop (or switch) completelySkips the rest of the current iteration only
Control goes to the statement after the loopControl goes to the next iteration (loop condition or update)
Used in loops and switchUsed only in loops
Needed to end each case of a switchCannot be used to end a switch case
#include <stdio.h>
int main(void)
{
    int i;
    printf("break   : ");
    for (i = 1; i <= 10; i++)
    {
        if (i == 5)
            break;          /* leaves the loop */
        printf("%d ", i);
    }
    printf("\ncontinue: ");
    for (i = 1; i <= 10; i++)
    {
        if (i == 5)
            continue;       /* skips only i = 5 */
        printf("%d ", i);
    }
    printf("\n");
    return 0;
}

Output:

break   : 1 2 3 4 
continue: 1 2 3 4 6 7 8 9 10

With break, the loop stops at 5; with continue, only 5 is skipped and the loop goes on up to 10.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Programming chapter 5 questions →