To skip the current iteration and continue with the next, use the continue statement in the body of a loop.
continue;
#include <stdio.h>
int main(void){
int guess = 1;
char response;
// ww w . j av a 2s .c o m
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;
}
The code above generates the following result.