continue在C语言编程语句的工作有点像break语句。代替强制终止,但是continue强制循环的下一个迭代发生,跳过之后的代码。
对于for循环,continue语句使循环的条件测试和增量部分来执行。对于while和do ... while循环,continue语句使程序控制传递给条件测试。
在C语言中 continue语句的语法如下:
continue;
#include <stdio.h>
int main ()
{
/* local variable definition */
int a = 10;
/* do loop execution */
do
{
if( a == 15)
{
/* skip the iteration */
a = a + 1;
continue;
}
printf("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