十五、流程控制之do循环

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章