如何使用 C# do while 循环?
do...while循环在循环结束时检查其条件。它类似于while循环,不同之处在于do...while循环保证至少执行一次。
创建一个dowhile循环-
do {
statement(s);
} while( condition );条件表达式出现在循环的末尾,因此statement(s)in循环在测试条件之前执行一次。
如果条件为真,则控制流跳回do,statement(s)循环再次执行。这个过程重复,直到给定的条件变为假。
以下是一个例子-
示例
using System;
namespace Loops {
class Program {
static void Main(string[] args) {
/* local variable definition */
int a = 50;
/* do loop execution */
do {
Console.WriteLine("value of a: {0}", a);
a = a + 1;
}
while (a < 20);
Console.ReadLine();
}
}
}输出结果value of a: 50
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短