switch ... semantics
switch ... semantics
- Switch statement is used when there are more two alternatives to select from..
- selector is an ordinal expression: That means that the values it can take should be finite, countable: integer, char, bool types are acceptable but not float.
- The selector type and case label type should be same.
- Each case label must be distinct.
- The selector expression is evaluated and compared to each of the case labels.
- If the value of the selector is one of the case labels, say label x, then the statementsx is executed.