Caitlin-havener Posted February 26, 2011 Share Posted February 26, 2011 How would the server process the following 'code' (pseudocode here):some stuff initializedswitch($something){case '':...case 'A':...case 'B':...}some other stuff;printing stuff out;Kay, so say that case 'A' is met so it runs that code, then it runs the code after the switch statement every time right? Even if I send it back up to case 'A' or case 'B' after that? Link to comment Share on other sites More sharing options...
birbal Posted February 26, 2011 Share Posted February 26, 2011 switch($something){case 'A':echo $something;break;case 'B':echo $something;break;case 'C':echo $something;break;} watch out the break statement now it will try to match those case once it found it will execute the body of the case. after that when it will see break; it will come out of the swicth case and will execute the next line.without the break statement i will execute all the body part of each case after it founds any match. and it will go untill it reaches the end of the case. after that it will come out from the case and execute the next line switch($something){case 'A':echo $something;case 'B':echo $something;case 'C':echo $something;} if $something='B'output will be B B (second B is from case 'C':more details here Link to comment Share on other sites More sharing options...
Caitlin-havener Posted February 26, 2011 Author Share Posted February 26, 2011 I meant to put the breaks in there. I'm just wondering if the code after the switch case is executed each time a case is met (say a button is pushed). Is the code before the switch case ever executed again? Link to comment Share on other sites More sharing options...
Ingolme Posted February 26, 2011 Share Posted February 26, 2011 Once the switch has been evaluated, the program keeps running normally.A switch is not a loop, it's a conditional. Link to comment Share on other sites More sharing options...
thescientist Posted February 26, 2011 Share Posted February 26, 2011 I meant to put the breaks in there. I'm just wondering if the code after the switch case is executed each time a case is met (say a button is pushed). Is the code before the switch case ever executed again?you could think of a switch statement as a really (potentially long) explicit if/else statement. if($something == '"'){ ...}else if($something == 'A'){ ...}else if($something == 'B'){ ...}else{ //default}; Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.