如果语句跳过条件

时间:2014-05-21 19:21:20

标签: c# if-statement error-handling skip

我有一些代码,但if条件是跳过而且没有被执行,即使它是真的。我的代码用简单的术语表示如下:

for(int i = 13;i<anarray.length;i++)
    if(i == 13)
    {
      for(w = i;w>12;w--)
      {
        if(anarray[w] > 0)     //the program skips this line completely even though the element is greater than 0
        { 
            //do some adding
        }
        if(anarray[w] < 0)
        {
            //do some other adding
        }
      }
    }

以下图片应该有所帮助:

调试1: enter image description here

调试2: enter image description here

调试3: enter image description here

调试4: enter image description here

1 个答案:

答案 0 :(得分:2)

您的问题来自

for(int w= m_RSISSteps - 1; w > m_RSISteps - 1; w--)

您刚刚将w定义为等于m_RSISteps - 1,因此<检查的结果为false,for循环永远不会执行。可能您的支票需要更正,也许您打算w >= 0或使用除m_RSISteps以外的其他变量。

要将其转换为“简化示例”,就像你做的那样

for(int i = 12;i<anarray.length;i++) //These should be 12 not 13 based off of your images.
    if(i == 12)
    {
      for(w = 12;w>12;w--) //HERE
      {
        if(anarray[w] > 0)     //the program skips this line completely even though the element is greater than 0
        { 
            //do some adding
        }
        if(anarray[w] < 0)
        {
            //do some other adding
        }
      }
    }