BREAK; question in SWITCH CASE

Just a quick question. Is it necessary to have a BREAK following the arguments when using SWITCH/CASE? If it is necessary what happens when you run the sketch without it(assuming it compiles correctly)?

I'm trying to troubleshoot a library. Thanks.

Without break; the switch structure will continue to run every case after the one that was first run.

break; just exits the switch.

So, not necessary, but for most cases (heh) you would want to have the break; statement.

Thanks sciguy

I have excluded a break in a switch case before, but it was a very strange circumstance. essentially I needed it to:

if 1, run 1, 2, 3
if 2, run 2, 3
if 3, run 3

so i only had a break at 3.

It never actually worked though, I ended up having to make a nested if loop instead.

case 1: do1(); // fallthrough
case 2: do2(); // fallthrough
case 3: do3(); break,

should have worked, given the problem as described, bleedscarlet.

Just to clarify something then, this excerpt is taken from the TWI library:

  switch(TW_STATUS){
    // All Master
    case TW_START:     // sent start condition
    case TW_REP_START: // sent repeated start condition
      // copy device address and r/w bit to output register and ack
      TWDR = twi_slarw;
      twi_reply(1);
      break;

If TW_STATUS == TW_START or TW_STATUS == TW_REP_START then it will execute case TW_REP_START?

If TW_STATUS == TW_START or TW_STATUS == TW_REP_START then it will execute case TW_REP_START?

Yes.

Well that explains a lot...thx.