concept switch in category c

appears as: switch, switch, switches
Modern C

This is an excerpt from Manning's book Modern C.

[Exs 6] Test the example switch statement in a program. See what happens if you leave out some of the break statements.

Syntactically, a switch is as simple as

   switch (expression) statement-or-block


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":3},{\"line\":0,\"ch\":9}],[{\"line\":0,\"ch\":33},{\"line\":0,\"ch\":35}]]"}
!@%STYLE%@!

and its semantics are quite straightforward: the case and default labels serve as jump targetsC. According to the value of the expression, control continues at the statement that is labeled accordingly. If we hit a break statement, the whole switch under which it appears terminates, and control is transferred to the next statement after the switch.

By that specification, switch statements can be used much more widely than iterated if-else constructs: