如何使用 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 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短