While语句:while(布尔表达式) 嵌入语句;
注意:while语句能够按照不同的条件执行一个嵌入语句0次或多次。
举例:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace While循环
{
class Program
{
static void Main(string[] args)
{
int myInt = 0;
while (myInt < 10)
{
Console.WriteLine("{0}", myInt);
myInt++;
}
}
}
}
输出为:
0
1
2
3
4
5
6
7
8
9