Swtich (newb)

Hello, I'm working on a program in which I use a switch with quite some cases, though quite some cases have the same behaviour so I wanted to ad them like:

switch(xx) {

case 4, 16, 64: ** ** break;

case 8, 24: ** ** break;

but that is not allowed in the syntax, how should I do this?

try this:

switch(xx) { case 4: case 16: case 64: // do something when xx is equal to 4,16,or 64 break;

case 8: case 24: // do something when xx equals 8 or 24 break; }

oh ofcourse! stupid. Thanks mate!

One of the great things about programming is how easy something becomes once you know how.

And one of the frustrations is that there is always something still to learn, usually standing in the way of completing the next project ;)

I also found that this can come in handy just to shorten the text of the switch . . .

case 0 ... 9:  // ellipses (not std. C but works for Arduino)
// something for case 1,2,3,4,5,6,7,8,9
break;