c# while迴圈_counter++_內含if判斷_break

wisdomone1發表於2012-03-01
//while迴圈
counter = 0;
            while (counter < this._deductSchedView.Count)
            {
                DeductSchedViewItem CSS0S0000 = this._deductSchedView[counter];
                if (this._deductSchedNbr == Convert.ToInt64(CSS0S0000.DeductSchedNbr))
                {
                    this.grdList.Rows[counter].Selected = true;
                    break;
                }
                counter++;
            }



            //測試while迴圈及內嵌if及break
            //實現功能:如果自1新增到,就列印顯示在文字框中,否則繼續累加
            int counter = 0;
            while (counter < 11)
            {
                if (counter==10)
                {
                    MessageBox.Show("已經累加到");
                    //經測試是break是退出其while迴圈,執行while下面的程式碼 MessageBox.Show("哈哈break之後執行的程式碼");
                    break;
                }
                //否則沒到繼續累加counter
                counter++;
            }

            //為了測試break是否跳出其所在的while迴圈加下述程式碼
            MessageBox.Show("哈哈break之後執行的程式碼");
        }

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-717468/,如需轉載,請註明出處,否則將追究法律責任。

相關文章