在C#中,while循环的基本语法如下:
while (condition){ // 代码块}其中,condition 是一个布尔表达式,用于测试循环条件。当条件为 true 时,执行循环体内的代码块。当条件为 false 时,跳出循环,继续执行循环之后的代码。
以下是一个简单的示例:
int counter = 0;while (counter < 5){ Console.WriteLine("Counter: " + counter); counter++;}这段代码将输出:
Counter: 0Counter: 1Counter: 2Counter: 3Counter: 4 



