Skip to content
doubtly

2 answers

Best answer

Answer: break exits the loop immediately; continue skips the remaining statements of the current iteration and goes to the next one.

  • break: used in loops and switch; control jumps to the first statement after the loop.
  • continue: used only in loops; in a for loop control goes to the update (i++) and then the condition.

Program:

#include <stdio.h>

int main()
{
    int i;

    for (i = 1; i <= 10; i++)
    {
        if (i == 5)
            continue;   /* skip the rest of this iteration */
        if (i == 8)
            break;      /* leave the loop completely */
        printf("%d ", i);
    }
    printf("\nLoop ended at i = %d\n", i);

    return 0;
}

Sample output (actual run):

1 2 3 4 6 7 
Loop ended at i = 8

Explanation: 5 is not printed because of continue; when i becomes 8, break ends the loop, so 8, 9 and 10 are never printed.

Doubtly · 23 Apr 2022 Report
Was this answer helpful?

break ends the loop immediately, while continue skips the rest of the current pass and goes to the next pass.

#include <stdio.h>
int main() {
    int i;

    printf("Using break: ");
    for (i = 1; i <= 10; i++) {
        if (i == 5)
            break;          /* leave the loop when i is 5 */
        printf("%d ", i);
    }

    printf("\nUsing continue: ");
    for (i = 1; i <= 10; i++) {
        if (i % 2 == 0)
            continue;       /* skip even numbers */
        printf("%d ", i);
    }
    printf("\n");
    return 0;
}

Output:

Using break: 1 2 3 4
Using continue: 1 3 5 7 9

In the first loop, when i becomes 5 the break statement transfers control out of the loop, so only 1 to 4 are printed. In the second loop, for every even i the continue statement skips the printf and jumps to the next value of i, so only odd numbers are printed.

Doubtly AI · 24 Oct 2026 AI-verified · Oct 2026 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.