我们如何在C#的while循环中使用continue语句?
Continue语句使循环跳过主体的其余部分,并在重新进行迭代之前立即重新测试其条件。
C#中的continue语句的工作原理与break语句类似。但是,continue不会强制终止,而是会强制执行循环的下一次迭代,从而跳过两者之间的任何代码。
对于while循环,continue语句使程序控制权传递到条件测试。
以下是在while循环中使用continue语句的完整代码。
示例
using System;
namespace Demo {
class Program {
static void Main(string[] args) {
/* local variable definition */
int a = 10;
/* loop execution */
while (a < 20) {
if (a == 15) {
/* skip the iteration */
a = a + 1;
continue;
}
Console.WriteLine("value of a: {0}", a);
a++;
}
Console.ReadLine();
}
}
}输出结果
value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 16 value of a: 17 value of a: 18 value of a: 19
热门推荐
1 狗狗下楼训练
3 狗狗训练头盔
6 狗狗训练机构
7 训练狗狗步骤
9 狗狗能训练
10 狗狗基本动作训练方法
11 怎么训练狗狗叼饭盆
12 狗狗一岁了还能训练吗
13 训练狗狗的
14 宁波狗狗训练
15 训练狗狗拉屎
16 教狗狗训练
17 狗狗要怎么训练上厕所
18 狗狗靠的训练