A break statement exits the nearest enclosing iteration or switch statement immediately. In a loop, it skips termination-condition reevaluation and the remaining statements in the current iteration; in a switch, it transfers control to the statement after the switch. section 3.2 section 3.3
Stopping an iterative approximation
while (true) { double prod = a*x; if (fabs(1.0 - prod) < ε) { break; } x *= (2.0 - prod); } The loop computes the product, tests whether the approximation is close enough, and exits without performing another update when the test succeeds. section 3.2
Use break deliberately in these control-flow contexts:
- Place it inside a loop when a condition discovered during the body determines that iteration should stop. section 3.2
- Place it in a switch case when execution should not fall through into subsequent case statements. section 3.3 section 3.4
- Distinguish it from continue: continue skips the rest of the current loop body but reevaluates the loop condition. section 3.2
while (true) {
double prod = a*x;
if (fabs(1.0 - prod) < ε) { // Stops if close enough
break;
}
x *= (2.0 - prod); // Heron approximation
}
View a compact loop example that separates computation, stopping-condition evaluation, and the update controlled by break. section 3.2






