private short m_RuntimeRows;
short theInt16_1;for (theInt16_1 = 0; (theInt16_1 < this.m_RuntimeRows); theInt16_1 = ((short) (theInt16_1 + 1)))
{}
上面这段代码,我知道是个循环,但是看不懂是什么意思。谁能帮我解释一下吗?

解决方案 »

  1.   

    循环m_RuntimeRows次数,估计是延时,空循环在那浪费点时间
      

  2.   

    private short m_RuntimeRows;
    short theInt16_1;
     
    for (theInt16_1 = 0; theInt16_1 < m_RuntimeRows; theInt16_1++)
    {} 和这个写法完全一样的效果。
    theInt16_1 = theInt16_1 + 1;因为short和int相加,结果会隐试转换为int,所以前面要加一个类型转换。
      

  3.   

    for (theInt16_1 = 0; (theInt16_1 < this.m_RuntimeRows); theInt16_1 = ((short) (theInt16_1 + 1)))
    theInt16_1 = 0 设置初始值
     (theInt16_1 < this.m_RuntimeRows) 边界条件,括号可以不写,估计作者怕影响后面代码
    theInt16_1 = ((short) (theInt16_1 + 1)) 让theInt16_1 加1,强制转换为sort,防止类型自动被转换为int,
      

  4.   

    无论什么for循环,都是三段式的:
    for (循环开始之前执行; 判断循环是否应该继续的条件表达式; 在每次循环结束之后执行)
      

  5.   

    所以一个for循环可以写成while或者goto的形式:
    for (循环开始之前执行; 判断循环是否应该继续的条件表达式; 在每次循环结束之后执行)
    {
        循环体
    }
    循环开始之前执行
    while (判断循环是否应该继续的条件表达式)
    {
        循环体
        在每次循环结束之后执行
    }
    循环开始之前执行
    label_loopstart:
    if (判断循环是否应该继续的条件表达式)
    {
        循环体
        在每次循环结束之后执行
    }
    else
    {
        goto label_loopend:
    }
    goto label_loopstart:
    label_loopend:
      

  6.   

    m_RuntimeRows没有赋值,默认==0;
    theInt16_1 =0
    theInt16_1 < this.m_RuntimeRows加上这个条件,循环根本不会执行,毫无意义,也不会浪费时间。
      

  7.   

    runtimerows 应该就是延时了...
      

  8.   

    非常感谢大家的帮助,尤其是版主无私的指点。不过,我觉得这不是空循环,因为确实运行到里面,并且有错误提示。把代码贴出来,只是为了告诉大家,有这种特殊情况。也许是我还不理解或者没有掌握的技术?
              private short m_RuntimeRows;
    private void GeneralDraw ()

    {
    int theInt32_2;
    short theInt16_3;
    short theInt16_2;
    short theInt16_1;                 string theString1;
    int theInt32_1;
    if (! this.m_FirstDraw)
    {
    this.g.FillRectangle (this.m_BackBrush, ((int) this.m_LeftPixels), ((int) this.m_TopPixels), ((int) this.m_WidthPixels), ((int) this.m_HeightPixels));
    }
    if ((this.m_Orientation == enumOrientation.or0) || (this.m_Orientation == enumOrientation.or180))
    {
    this.m_CurrX = this.m_LeftMargainPixels;
    this.m_CurrY = this.m_TopMargainPixels;
    }
    else
    {
    this.m_CurrX = this.m_TopMargainPixels;
    this.m_CurrY = this.m_LeftMargainPixels;
    }
    if (this.m_FirstDraw)
    {
    this.BinaryCompact ();
    }
    theInt32_1 = 0;
    theString1 = null;
    for (theInt16_1 = 0; (theInt16_1 < this.m_RuntimeRows); theInt16_1 = ((short) (theInt16_1 + 1)))
              {
    if ((this.m_Orientation == enumOrientation.or0) || (this.m_Orientation == enumOrientation.or180))
    {
    this.m_CurrX = this.m_LeftMargainPixels;
    }
    else
    {
    this.m_CurrX = this.m_TopMargainPixels;
    }
    theInt16_2 = ((short) (theInt16_1 * this.m_ModuleHeightPixels));
    theInt16_3 = ((short) (- (((this.m_RuntimeRows - theInt16_1) - 1) * this.m_ModuleHeightPixels)));
    theString1 = this.GetPattern (130728);
    this.DrawChar ("bwbwbwbw", theString1, theInt16_2, theInt16_3);
    theString1 = this.GetPattern (BarcodePDF417.PDF417_BITS[(theInt16_1 % 3), ((int) this.GetRowStart (theInt16_1))]);
    this.DrawChar ("bwbwbwbw", theString1, theInt16_2, theInt16_3);
                             for (theInt32_2 = 0; (theInt32_2 < this.m_Columns); theInt32_2 += 1)
    {
                        theString1 = this.GetPattern(BarcodePDF417.PDF417_BITS[(theInt16_1 % 3), ((int)this.m_EncodedData[theInt32_1++])]);  //此处提示“索引超出了数组界限”,所以是运行到了这里。
                        this.DrawChar("bwbwbwbw", theString1, theInt16_2, theInt16_3);                 
    }
    if (! this.m_TruncatedSymbol)
    {
    theString1 = this.GetPattern (BarcodePDF417.PDF417_BITS[(theInt16_1 % 3), ((int) this.GetRowEnd (theInt16_1))]); this.DrawChar ("bwbwbwbw", theString1, theInt16_2, theInt16_3);
    this.DrawChar ("bwbwbwbwb", "711311121", theInt16_2, theInt16_3);
    }
    else
    {
    this.DrawChar ("bw", "11", theInt16_2, theInt16_3);
    }
    this.m_CurrY = ((short) (this.m_CurrY + this.m_ModuleHeightPixels));
    }
    }
      

  9.   

    说明一下,上面代码中有  <SPAN style="COLOR: #ff0000">标志的地方,是我特别标识出来的。是关键的几句代码。
      

  10.   

    你把人家大括号中的东西都省了贴上来,所以才有人误以为是延时,其实short类型的空循环,也延不多长时间,延时用thread.sleep更好。