2012-02-25 155 views
0

我很难看出为什么一种方式的作品和方式没有。switch语句中的if语句?

我有;

switch (key) 
     { 
      //If Game over Label is visible, enable the m and e buttons 
      if(mGameOverLabel->GetVisible()) 
      { 
       case 'm': case 'M': 
        ResetScreen(); 
        break; 

       case 'e': case 'E': 
       // //Exit the game 
        Stop(); 
        break; 
      } else { 

       case ' ': 
        mSpaceship->Shoot(); 
        break; 

       default: 
        break; 
      } 

对于M和E,即使mGameOverLabel在这个当前时间设置为false的情况下,我仍然可以按M和E和这些将根据方法反应,但如果我将其更改为这对M来说,它只会在我需要它的时候才起作用。我在这里错过了什么?

switch (key) 
     { 
      //If Game over Label is visible, enable the m and e buttons 

      case 'm': case 'M': 
       if(mGameOverLabel->GetVisible()) ResetScreen(); 
       break; 
      } 
+0

在swicth语句之前,你能做到吗? – Andrew 2012-02-25 17:01:00

+1

@安德鲁:什么? – Ryan 2012-02-25 17:02:23

回答

7

switch基本上没有一个goto到适当的情况下的标签。高于case的任何逻辑都不会被执行。

+0

啊,那会解释一切!谢谢! – r0bb077 2012-02-25 17:16:46