迭代语句是在程序中重复的执行,直到满足指定条件才停止的一段代码。当用户想重复执行某些语句时,可依据当前不同的任务,选择不同的循环语句使用。
while语句
while(条件表达式)
{
代码语句
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
int num = 1;
while(num<=50)
{
Console.WriteLine(num);
num++;
}
Console.ReadKey();
}
}
}
while语句在执行时,只有条件满足才进行循环。
本文详细介绍了while循环语句的使用方法及示例代码。通过一个简单的计数器例子展示了如何使用while循环来重复执行代码块,直到满足特定条件为止。
580

被折叠的 条评论
为什么被折叠?



