欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#中while循環(huán)語句用法實(shí)例詳解

 更新時(shí)間:2014年10月30日 14:41:35   投稿:shichen2014  
這篇文章主要介紹了C#中while循環(huán)語句用法,以實(shí)例形式詳細(xì)分析了while語句的用法,并對(duì)return,continue,break的區(qū)別做了進(jìn)一步的分析,需要的朋友可以參考下

本文實(shí)例講述了C#中while循環(huán)語句用法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

在C#中while循環(huán)是我們經(jīng)常會(huì)用到的一種循環(huán)語句,while循環(huán)特點(diǎn)是直到條件為零時(shí)才跳出循環(huán),當(dāng)然中間可以利用其它函數(shù)直接跳出,對(duì)于while的具體用法有必要做一個(gè)較為詳盡的分析。

先來說Foreach和For的區(qū)別,F(xiàn)oreach是針對(duì)對(duì)象進(jìn)行遍歷的,不需要定義循環(huán)次數(shù),但是有個(gè)缺點(diǎn),F(xiàn)oreach遍歷取的是只讀數(shù)據(jù),不能在Foreach中進(jìn)行對(duì)象的增刪改,而For循環(huán)就可以。這個(gè)改成while循環(huán)的代碼如下:

復(fù)制代碼 代碼如下:
int i=0;while(i<ds.Table["userreg"].Rows.Count){i++;}

示例如下:

復(fù)制代碼 代碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace 中斷循環(huán)
{
    class Program
    {
        static void Main(string[] args)
        {
            //100以內(nèi)拍七
            int i = 0;
            while (i < 100)
            {
                i++;
                if(i%7==0 || i%10==7||i/10==7)
                {
                    continue;
                }
                Console.WriteLine("{0}",i);
            }
            Console.ReadKey();
        }
    }
}

補(bǔ)充:

while中return,continue,break的區(qū)別:
return:退出main函數(shù)
continue:直接進(jìn)行下輪循環(huán)
break:直接跳出當(dāng)前循環(huán)

希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論