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
See Also
Previous
arrow_back
Do while operator