您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _16.流程控制之while循环
{
class Program
{
static void Main(string[] args)
{
/**
* while循环语句
* 其语法:
* while<Test>
* {
* <code to be looped>
* }
*
* 执行过程:
* 1. 计算<Test>布尔表达式的值;
* 2. 如果<Test>布尔表达式的值为true,则执行标记为循环的代码;
* 3. 如果<Test>布尔表达式的值为false,则退出循环执行循环结构外的代码;
* 4. 如果<Test>布尔表达式的值为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();
}
}
}免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。