The switch
statement in C is used to execute one of many code blocks based on the value of an expression. The basic syntax is:
expression
: The value to be evaluated.case value
: Each possible value the expression might take.break
: Exits the switch statement (optional, but often used).default
: The default case, executed if no case matches.
The switch
statement helps simplify multiple if-else
conditions.