views:

26

answers:

1

I have the following:

switch(state) {
  case MyStates.StateA:
     //do something
     break;
  case MyStates.StateB:
     //do something
     break;
  case MyStates.StateC:
     //do something
     break;

}

Say StateB and StateC both need to process the same bit of code, how can I avoid the duplication? Note that I cannot set MyStates.StateB = MyStates.StateC; they have to differ and can also be of different types. I want to do something like the following illegal statement:

case MyStates.StateB || case MyStates.StateC :
+8  A: 
switch(state) {
  case MyStates.StateA:
     //do something for A
     break;
  case MyStates.StateB:
  case MyStates.StateC:
     //do something for B and C
     break;
}
KennyTM
For completeness, you should also include the default: / break; block as well.
Mike Clark