The switch()β¦ statement revisited
The switch()β¦
statement is best used when we have a single value that can only have a specified set of values. Doesn't that sound like an enumerated type? It should and, happily, it does.
Using the switch()β¦
statement to evaluate an enumerated type simplifies the intent of our code and helps to prevent some troublesome situations. Here is the shapeFunc()
function revisited using the switch()β¦
statement:
enum result_code shapeFunc( enum shape aShape) {
...
switch( aShape )
{
case triangle:
...
break;
case rectangle:
...
break;
case circle:
...
break...