Switch returning two cases

The following switch statement prints out 75% and 100%, why?

switch (128) {
        case 0xE0: Serial.println("25%");
        case 0xC0: Serial.println("50%");
        case 0x80: Serial.println("75%");
        case 0x00: Serial.println("100%");
        }

No breaks

Thanks. I haven't used "switch" for a while, I should have checked before posting.

Just for fun, and slightly smaller code,
You could be ‘clever’, and leave out the breaks to let the switch logic ‘fall through’...
Using something like
value += 25; // for each ‘case’, then a single print at the end...
Serial.print(value); Serial.println(‘%’);
You’ll need to flop the cases around so the value grows correctly..

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.