|
CS 3304: Comparative Languages
|
C/C++ Switch
switch (expression) {
case constant_expression_1 : statement_1;
...
case constant_expression_n : statement_n;
[default: statement_n+1]
}
- Design Choices (for switch):
- Control expression can be only an integer type
- Selectable segments can be statement sequences or blocks
- Construct is encapsulated
- Any number of segments can be executed in one execution of the construct (reliability vs. flexibility)
- Default clause for unrepresented values