continue语句在D编程语言的工作原理有点像break语句。而不是强迫终止,而是继续强制循环发生的下一次迭代,在两者之间跳过任何代码。
对于for循环中,continue语句会导致执行循环的条件测试和增量部分。对于while和do... while循环,continue语句使程序控制通行条件测试。
D语言continue语句语法如下所示:
continue;
import std.stdio; |
int main () |
{ |
/* local variable definition */ |
int a = 10; |
/* do loop execution */ |
do |
{ |
if( a == 15) |
{ |
/* skip the iteration */ |
a = a + 1; |
continue; |
} |
writefln("value of a: %d", a); |
a++; |
}while( a < 20 ); |
return 0; |
} |
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 |