重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

十六、流程控制之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://cqcxhl.com/article/pcojii.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP