十六、流程控制之while循环-古蔺大橙子建站
RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
十六、流程控制之while循环
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _16.流程控制之while循环
{
    class Program
    {
        static void Main(string[] args)
        {
            /**
             * while循环语句
             * 其语法:
             *  while
             *  {
             *      
             *  }
             *  
             * 执行过程:
             * 1. 计算布尔表达式的值;
             * 2. 如果布尔表达式的值为true,则执行标记为循环的代码;
             * 3. 如果布尔表达式的值为false,则退出循环执行循环结构外的代码;
             * 4. 如果布尔表达式的值为true时,则重复1~3步骤。
             * 
             * 特殊说明:
             * 1. do...while语句中的循环体至少被执行一次,而while语句中循环体可能不被执行。
             * 2. while语句后面不用书写分号。
             *
             */
             
            // 求2+4+...+10计算的结果。
            
            int i = 2, sum = 0;
            do
            {
                sum += i;
                i += 2;
            } while (i <= 10);
            
            Console.WriteLine("2+4+...+10 = {0}", sum);
            
            Console.ReadKey();
        }
    }
}

网站栏目:十六、流程控制之while循环
文章起源:http://scgulin.cn/article/pcojii.html