break — terminate a loop or switch
The break; statement terminates the nearest enclosing loop or switch statement. Execution continues after the terminated statement, rather than proceeding to the next loop iteration.
CKTIS / Knowledge base
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
The break; statement terminates the nearest enclosing loop or switch statement. Execution continues after the terminated statement, rather than proceeding to the next loop iteration.
The case keyword marks an entry point in a switch statement for a particular constant value. A label does not end a branch: without break or another transfer of control, execution continues onward, including through subsequent labels.
The catch keyword introduces an exception handler associated with try. Its parameter type determines matching, while catch (...) matches any exception and must appear last.
The class keyword declares or defines a class type that can combine data and member functions. Member access and inheritance access default to private, unlike struct, where both default to public.
compl is a built-in C++ alternative spelling of ~. For integer operands, it flips bits after integral promotions. It is not logical negation and requires neither a header nor a macro definition.
The concept keyword defines a named constraint on template arguments. It lets you reuse requirements checked during compilation and restrict overload availability without adding runtime checks.
const restricts modification through a particular name, reference, or pointer. Learn the difference between a pointer to const and a const pointer, and what const after a member function's parameter list means.
consteval declares an immediate function: its calls require constant evaluation, with exceptions that let such computations be composed. Unlike constexpr, it does not provide an ordinary runtime execution path for the function. if consteval distinguishes constant-evaluation contexts from runtime evaluation.
constexpr requires a constant initializer for a variable and allows a function to participate in constant expressions. It does not force every function call to be evaluated during compilation.
constinit requires static initialization of a variable with static or thread storage duration. It does not make the variable immutable: it constrains initialization, not subsequent assignments.
The continue; statement skips the remainder of the current iteration of the innermost enclosing loop. It does not terminate the whole loop: subsequent control flow depends on the loop kind, including execution of the step expression in a traditional for loop.
co_return finishes execution of a coroutine body and delivers its result to the promise object rather than returning it directly like ordinary return. The coroutine then proceeds to final_suspend(); its state's lifetime depends on the coroutine's ownership mechanism.
A co_yield expression passes its operand to the coroutine promise object's yield_value and awaits the result. In a generator, this exposes successive values without ending the function; whether execution actually suspends depends on the awaiting mechanism.
decltype specifies a type from an expression without executing it. It distinguishes an object's name from a general expression: decltype(x) can denote int, while decltype((x)) denotes int&.
The default keyword has two distinct uses: it selects a path in switch when no case matches, or, in an = default definition, asks the compiler to generate a function according to language rules. It does not mean that data members are automatically zeroed.
The do keyword starts a do-while loop: its body executes before the controlling expression is tested. The loop repeats while that expression evaluates to true. The trailing semicolon is required.
The else keyword introduces an optional branch of an if statement, selected when the condition is false. The spelling else if nests another if; braces make branch association explicit.
The enum keyword defines a distinct type with named constants. Learn the differences between enum and enum class, value numbering, and underlying-type selection.
The explicit specifier restricts constructors and conversion functions in implicit conversions while preserving deliberate object construction. Learn the distinction between direct- and copy-initialization, the special role of operator bool, and conditional explicit(condition).
The `export` keyword marks a module interface unit, exposes declarations to importers, or re-exports an import. Writing `export module M;` alone does not automatically export all subsequent declarations.
extern lets you declare variables and functions while separating a declaration from a definition. It does not mean that the definition must be in another file. It also appears in language linkage specifications such as extern "C" and in explicit instantiation declarations for templates.
The keyword false is a literal of type bool representing logical falsity. It can initialize flags and control conditions. Promotion to int produces 0, but false itself is not an integer literal.
The final specifier prevents further overriding of a virtual function or use of a class as a base class. These restrictions are checked at compile time. It does not make an object immutable and does not replace override.
The for keyword creates either a classic loop with initialization, a condition, and an update, or a range-based loop over elements. Choose the form according to whether you need explicit index control or access to successive elements.