Question about "break;"

If I have this segment of a switch case routine:

case 1: //fill saltwater reservoir
        if(digitalRead(freshwater_low_float_switch) == false && 
         saltwater_fill_flag == true)
        {
          digitalWrite(fresh_to_salt_pump, Off)
          saltwater_fill_flag == false;
          break;
        }
        if(digitalRead(saltwater_high_float_switch) == false &&
        saltwater_fill_flag == false)
        {
          saltwater_fill_flag == true;
          digitalWrite(fresh_to_salt_pump, On);
        }
        if(digitalRead(saltwater_high_float_switch) == true)
        {
          saltwater_fill_flag == false;
          digitalWrite(fresh_to_salt_pump, Off);
          wc_stage = 2;
        }
        break;

I know that the "break;" at the very end will cause the program to leave the switch case routine, but will the "break;" at the end of the first "If" statement cause the program to break out of the switch case or just the "If" statement? Basically if the first "If" statement evaluates to "true", I want it to leave the switch case and not continue on into the following "If" statements. Would a "return;" be better in this case?

you should be able to write a simple test program to just check that behaviour.

BTW you miss a break in the second if.

robtillaart: you should be able to write a simple test program to just check that behaviour.

BTW you miss a break in the second if.

I can put a break in, but it isn't needed because there shouldn't be an instance where both of those are true at the same time. I need it on the first "If" statement because the first and second "if" statements will likely be true at the same time and the second "if" statement undoes the first "If" statements action.

"break;" Jumps to the end of the following statements: switch(){} for(){} while(){} do{}while();

If it is contained within more than one of those statements it moves one step out (for lack of a better way of saying it). So for example:

while(1){
  if(something){
    break; //go to the end of the while(1) statement.
  }
}
while(1){
  while(2){
    if(something){
      break; //go to the end of the while(2) statement as it only steps out by one level.
    }
  }
}
switch(1){
case 1:
  while(1){
    if(something){
      break; //go to the end of the while(1) statement as it only steps out by one level.
    }
  }
  //this is the end of the while(1) statement
  if(boo){
    break; //go to the end of the switch
  }
  break; //go to the end of the switch
case default:
  //you can get away without a break here as we are already at the end
}
//This is end of switch

[quote author=Tom Carpenter link=topic=128184.msg964209#msg964209 date=1350754286] "break;" Jumps to the end of the following that the statements: switch(){} for(){} while(){} do{}while();

If it is contained within more than one of those statements it moves one step out (for lack of a better way of saying it). [/quote]

This is perfect! Thanks! So it sounds like my code will do what I want it to do which is exit the switch case imeediately if the first "if" statement is true.