What is true about a break?

2024

What is true about a break?

  1. A.

    Break stops the execution of entire program

  2. B.

    Break halts the execution and forces the control out of the loop

  3. C.

    Break forces the control out of the loop and starts the execution of next iteration

  4. D.

    Break halts the execution of the loop for certain time frame

Attempted by 2 students.

Show answer & explanation

Correct answer: B

Concept

A break statement is a jump / control-transfer statement used inside loop constructs (for, while, do-while) and switch blocks. When it executes, it immediately abandons the innermost enclosing loop or switch — skipping any remaining code in that iteration, the loop's condition check, and its increment step — and hands control to the very first statement that follows that loop or switch.

Applying it here

Trace a small loop that uses break:

  1. i = 1: the condition (i == 3) is false, so 1 is printed.

  2. i = 2: the condition is still false, so 2 is printed.

  3. i = 3: the break statement executes — the loop is exited immediately, without printing 3 and without running i = 4 or i = 5.

  4. Control moves straight to the first statement after the loop (for example, a print("done") placed right after it), which still runs normally.

So break both halts the loop early and forces control out to whatever comes right after it — the loop stops, but the rest of the program keeps running.

Why the other options don't fit

  • "Stops execution of the entire program" is too broad — break only exits the nearest enclosing loop/switch; the program keeps running right after it, as the trace above shows.

  • "Starts the execution of the next iteration" describes continue, which skips the rest of the current iteration's body and resumes the loop's condition check — the opposite of leaving the loop.

  • "Halts execution for a certain time frame" would describe a delay/sleep call — break causes an immediate, permanent exit, not a pause.

The option that matches this behaviour is the one stating that break halts execution and forces control out of the loop.

Explore the full course: Cognizant Preparation