Hello, I have a question about using the switch() statement: when I use more than one 'case' for a single action, should I 'break' all the cases or simply using a single 'break' will end all the cases? bad english + I don't know how to explain = let me explain with a sample
That is, I have used 2 'case', for 0 and for 1; then should I use also twice 'break'? I see that the program runs without error, and also I have find on the net lots of codes that uses only one 'break' after start several 'case', that also works without error; sometimes I used also this method, only breaking one time at the end and my simple programs run without problem. I was wondering which is the right way to do it? Should I 'break' each 'case'?Code:#include <conio.h> int main() { int a=1; switch(1) { case 0: case 1: { //whatever for 0 or 1 } break; break; case 2: { //for 2 } break; } getch(); return 0; }
Thank's in advance
niara