我们如何在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 狗狗技能训练
5 如何训练狗狗笑
6 狗狗训练排便
9 狗狗响片训练
10 如何训练狗狗不捡食
11 狗狗尿训练
12 怎么训练狗狗找东西
13 狗狗训练站立
14 狗狗训练飞盘
15 鞍山狗狗训练
16 怎样训练泰迪狗狗谢谢
17 狗狗外出训练
18 怎么训练金毛狗狗大小便