学习C – C continue
要跳过当前的迭代并继续下一个,请在循环体中使用continue语句。
continue;
例子
#include <stdio.h>
int main(void){
int guess = 1;
char response;
printf("is your number %d?\n", guess);
while ((response = getchar()) != "y") /* get response */
{
if (response == "n")
printf("Well, then, is it %d?\n", ++guess);
else
printf("Sorry, I understand only y or n.\n");
while (getchar() != "\n")
continue; /* skip rest of input line */
}
return 0;
}
上面的代码生成以下结果。