C#入门5.4——迭代语句之while语句

来源:互联网 发布:js post html代码 编辑:程序博客网 时间:2024/06/01 09:53

迭代语句是在程序中重复的执行,直到满足指定条件才停止的一段代码。当用户想重复执行某些语句时,可依据当前不同的任务,选择不同的循环语句使用。

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语句在执行时,只有条件满足才进行循环。




0 0
原创粉丝点击