Luouy~羽林
学问如逆水行舟,不进则退; 有知识的人不实践,等于一只蜜蜂不酿蜜; 我们可以由读书而收集知识,但必须利用思考把糠和谷子分开

foreach循环

// An array of integers
int[] array1 = {0, 1, 2, 3, 4, 5};

foreach (int n in array1)
{
    System.Console.WriteLine(n.ToString());
}


// An array of strings
string[] array2 = {"hello", "world"};

foreach (string s in array2)
{
    System.Console.WriteLine(s);
}

 

for循环

 

// An array of integers
int[] array1 = {0, 1, 2, 3, 4, 5};

for (int i=0; i<6; i++)
{
    System.Console.WriteLine(array1[i].ToString());
}


// An array of strings
string[] array2 = {"hello", "world"};

for (int i=0; i<2; i++)
{
    System.Console.WriteLine(array2[i]);
}

 

 

while循环

 

// An array of integers
int[] array1 = {0, 1, 2, 3, 4, 5};
int x = 0;

while (x < 6)
{
    System.Console.WriteLine(array1[x].ToString());
    x++;
}


// An array of strings
string[] array2 = {"hello", "world"};
int y = 0;

while (y < 2)
{
    System.Console.WriteLine(array2[y]);
    y++;
}

 

Do while循环

 

// An array of integers
int[] array1 = {0, 1, 2, 3, 4, 5};
int x = 0;

do
{
    System.Console.WriteLine(array1[x].ToString());
    x++;
} while(x < 6);


// An array of strings
string[] array2 = {"hello", "world"};
int y = 0;

do
{
    System.Console.WriteLine(array2[y]);
    y++;
} while(y < 2);

posted on 2008-11-07 15:11  羽林.Luouy  阅读(8330)  评论(1编辑  收藏  举报