Select one of many code blocks to be executed based on the value of a single variable.
The `switch` statement in C provides a clean and efficient way to handle multi-way branching, where you need to execute different code based on the value of a single integer or character variable. It's often a more readable alternative to a long `if-else if-else` ladder. The `switch` statement begins with the `switch` keyword followed by the variable (or expression) to be evaluated, enclosed in parentheses. The body of the `switch` is a block of code containing one or more `case` labels. Each `case` is followed by a constant value and a colon. When the `switch` statement executes, the value of its expression is compared with the constant value of each `case`. If a match is found, the program jumps to the code following that `case` label and continues executing from there. A critical keyword within a `switch` statement is `break`. The `break` statement is used to exit the `switch` block. If you omit `break` at the end of a `case`, execution will 'fall through' to the next `case`'s code block, which is sometimes intentional but often a source of bugs. It's a good practice to always include a `break` unless you specifically want the fall-through behavior. Additionally, a `switch` statement can have an optional `default` case. The code under the `default` label is executed if the expression's value does not match any of the `case` constants. This acts as a catch-all, similar to the final `else` in an `if-else` ladder.