simplified switch satement

Hi all,
Please look at the code below:
1
2
3
4
5
6
7
8
9
switch(input) 
{
case 'a' : doA();
break;
case 'b' : doB();
break;
case 'c' : doC();
break;
}

How can I implement an extra action when, say A/a and B/b are pressed, but not when C is pressed.
Do I have to put this action seperetely for every case, or is there a shorter way to do this ( I have a lot of cases in my current code )
I tried something like this, but it doesn't work.
1
2
3
4
5
6
7
8
9
10
11
switch(input) 
{
case 'a' : doA();
case 'b' : doB();
{
doExtraAction();
}
break;
case 'c' : doC();
break;
}

Is there any way to accomplish something like I described? Thanks in advance
Not really. Well, I can think of some horrible code convolutions you could use, but I wouldn't recommend them.

You'll need to change to using a good-old-fashioned if/else-if/else:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
if ( (input == 'a') || (input == 'b')
{
  if (input == 'a')
  {
    doA();
  }
  else
  {
    doB();
  }
  doExtraAction();
}
else if (input == 'c')
{
  doC();
}

Topic archived. No new replies allowed.