The keyword continue

The keyword continue is used only in the body of loop.
It is used to move control at termination condition in the case of while and do-while loop. continue is used in for loop to transfer control at flow part (increment/decrement).







Example

int main()
{
int x;
while(1)
{
printf(“Enter an even number”);
scanf(“%d”,&x);
if(x%2==1)
continue;
else
{
printf(“This is the correct value”);
break;
}
}
return(0);
}


In the above program, condition of while loop is always evaluated as TRUE. Any non-zero number is considered as TRUE and zero is considered as FALSE. The loop only ends at the execution of break. If the user enters an odd number condition x%2==1 becomes TRUE, then continue works. Continue transfers the control at while loop condition.
As long as user enters odd number, continue works every time, but when user enters an even number, break terminates loop

Keyword continue
Tagged on: