Break Operator

Overview

The break operator is used to terminate the execution of the nearest nested outward switch, while, do-while, or for operator. Upon termination, control is passed to the operator that immediately follows the terminated one.

A primary use case for the break operator is to exit a loop prematurely when a specific condition is met, such as finding a desired value.

Syntax

break;

Example

// Searching for the first zero element in an array
int i;
for(i = 0; i < array_size; i++)
  if(array[i] == 0)
    break;

Related Concepts

  • [Initialization of Variables](/basis/variables/initialization)
  • [Visibility Scope and Lifetime of Variables](/basis/variables/variable_scope)
  • [Creating and Deleting Objects](/basis/variables/object_live)
  • See Also

  • [Continue Operator](/basis/operators/continue)
  • [Switch Operator](/basis/operators/switch)
  • [Loop Operator while](/basis/operators/while)
  • [Loop Operator for](/basis/operators/for)
  • [Loop Operator do while](/basis/operators/dowhile)