Namespaces
Variants

break statement

From cppreference.com

Causes the enclosing for, while or do-while loop or switch statement to terminate.

Used when it is otherwise awkward to terminate the loop using the condition expression and conditional statements.

Syntax

attr-spec-seq (optional) break ;
attr-spec-seq - (C23) optional list of attributes, applied to the break statement

Appears only within the statement of a loop body (while, do-while, for) or within the statement of a switch.

Explanation

After this statement the control is transferred to the statement or declaration immediately following the enclosing loop or switch, as if by goto.

Keywords

break

Notes

A break statement cannot be used to break out of multiple nested loops. The goto statement may be used for this purpose.

Example

#include <stdio.h>

int main(void)
{
    int i = 2;
    switch (i)
    {
        case 1: printf("1");
        case 2: printf("2");