MCS-201 · Unit 3

Decision and Loop Control Statements

Section 7 of 7

Block 1 · Unit 3Decision and Loop Control Statements10 min · Section 7 of 7

3.7Jump Statements: break, continue and goto

Covers IGNOU MCS-201 §3.4, 3.5, 3.6

Sometimes a loop should stop early (the answer has been found) or skip one item (an invalid record) without stopping. C’s jump statements break and continue do this. The older goto statement can jump almost anywhere in a function and is generally avoided.

break

break immediately ends the innermost enclosing loop (or switch); execution continues with the first statement after it.

In nested loops, break leaves only the loop it is in, not the outer loops. break is different from the library function exit(), which ends the whole program.

continue

continue skips the rest of the current repetition and starts the next one:

  • In a while or do–while loop, control goes to the condition test.
  • In a for loop, control goes to the update part, then to the condition.

goto and labels

goto label; transfers control to the statement marked label: in the same function. A label is an identifier followed by a colon.

goto makes programs hard to follow (the “spaghetti code” of Unit 1). Structured statements (if, loops, break, continue, functions) can do everything it does. Its one accepted use is jumping out of deeply nested loops to a single exit or clean-up point.

Comparison

StatementEffectUsed in
breakLeaves the innermost loop or switchLoops, switch
continueSkips to the next repetition (via the update in for)Loops only
goto labelJumps to a labelled statement in the same functionAnywhere in a function (avoid)
exit(n)Ends the whole programAnywhere (library function in <stdlib.h>)

Key takeaways

  • break ends the innermost loop or switch immediately.
  • continue ends the current repetition; in for loops, the update still runs.
  • goto jumps to a label in the same function; structured code avoids it.
  • exit() ends the whole program, unlike break.

Practice questions

Answer on paper first, then check. The explanation matters more than the letter you chose.

Question 1 · multiple choice

What does break do inside a loop that is nested in another loop?

Show answer

Answer: B. Ends only the innermost loop

break leaves only the loop that directly contains it; the outer loop continues. Ending the program is what exit() does.

Question 2 · multiple choice

How many times is “hello” printed (Check Your Progress 3)?

C · hello_count.c
#include <stdio.h>

int main(void)
{
    int i = 5;
    while (i) {
        i = i - 1;
        if (i == 3)
            continue;
        printf("hello\n");
    }
    return 0;
}
Show answer

Answer: C. 4

i takes the values 4, 3, 2, 1, 0 inside the body; only at 3 is the print skipped, so “hello” appears 4 times. The update happens before continue, so the loop still ends.

Question 3 · multiple choice

What does this program print (Check Your Progress 3)?

C · sum_break.c
#include <stdio.h>

int main(void)
{
    int num, sum;
    for (num = 2, sum = 0; ; ) {
        sum = sum + num;
        if (num > 10)
            break;
        num = num + 1;
    }
    printf("%d\n", sum);
    return 0;
}
Show answer

Answer: B. 65

The numbers 2 to 11 are added (11 is added before the break test succeeds): 2 + 3 + … + 11 = 65. Stopping at 10 would give 54.

Question 4 · multiple choice

In a for loop, where does continue send control?

Show answer

Answer: D. To the update expression, then the condition

continue jumps to the end of the body, so a for loop’s update still runs before the condition is tested again.

Question 5 · multiple choice

Which statement cannot be used inside a switch that is not inside any loop?

Show answer

Answer: B. continue

continue belongs to loops; a switch alone has no “next repetition”. break is valid in a switch.

Question 6 · short answer

Explain the difference between break and continue using a loop that runs i from 1 to 5 and tests i == 3, giving the output of each version.

Show worked answer

With for (i = 1; i <= 5; i++) { if (i == 3) break; printf("%d ", i); }, the loop stops completely when i is 3, so the output is 1 2. With continue instead of break, only the repetition for 3 is skipped and the loop carries on, so the output is 1 2 4 5. break leaves the loop; continue moves on to the next value.

↑ ↓ move↵ openTab switch type