From: "Michael W. Ryder" <_mwryder@...> Date: 2008-08-29T03:55:20+09:00 Subject: Re: Having a difficult time with Case statements. Sebastian Hungerecker wrote: > Michael W. Ryder wrote: >> I think what you were trying to do >> would have worked in C as the case statements keep executing until they >> hit a break. > > In C if there is no break it will fall through, yes, but that would hardly > result in the behaviour the OP wanted. Take this for example: > > #include > int main(int argc, char** argv) { > int i = 0; > switch(i) { > case 0: > i = 2; > case 1: > printf("i is one (except it's not)\n"); > case 2: > break; > } > return 0; > } > > I assume the OP would want that to execute the 0 case and then the 2 case, but > it executes all three. I also assume that if the 2 case would set i to 0 > again, the OP would want it to start over again, which it also won't. > From the looks of the code that I was tracing selecting '2' would set the state to '1' which was the next step in the case statement. Obviously this would not have worked for every selection but it looked like he was trying to use C's case statement behavior. > HTH, > Sebastian