如何使用 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 2026新年的简短祝福语
16 金婚祝福语大全简短唯美
17 升学宴同学祝福语简短
18 中考祝福语 简短 签状