csharp 循环(while,for,do)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 循环(while,for,do)相关的知识,希望对你有一定的参考价值。

int i = 0;
while (i < 10)
  {
    Console.WriteLine(i);
    i++;
  }
//general form
for (initialization; Boolean expression; update control variable)
statement

//example
for (int i = 0; i < 10; i++)
{
Console.WriteLine(i);
}

//example 2
//omit increment and declaration of variables
int i = 0;
for (; i < 10; )
{
Console.WriteLine(i);
i++;
}

//example 3
//declare more than one variable
for (int i = 0, j = 10; i <= j; i++, j--)
{
...
}
int i = 0;
do
{
Console.WriteLine(i);
i++;
}
while (i < 10);

以上是关于csharp 循环(while,for,do)的主要内容,如果未能解决你的问题,请参考以下文章

csharp 基本do while循环的示例。

for while do-while三种循环体的特点和缺点

for 循环与while循环的区别

Java 循环结构 - for, while 及 do...while

Java 循环结构 - for, while 及 do...while

while,do while,for循环语句