Learn continue statement in best way possible

continue statement in C

In C program continue statement is use to force loop to stop current iteration and start executing next iteration.

In simple terms continue statement is use to stop current execution of loop and start with next iteration we can use continue with if-else statement and when certain condition is matched we can start next iteration.

continue-statement-itvoyagers
ITVoyagers

Example of continue statement with while loop

  #include<stdio.h>
void main()
{
int i=0;
while(i<=5)
{
i++;
if(i == 3)
{
continue;
}
printf("%d ITVoyagers n",i);
}
}

Output:

  1 ITVoyagers
2 ITVoyagers
4 ITVoyagers
5 ITVoyagers

In above example while loop will starting iterating  because initial condition is valid and it will print value of i followed by ITVoyagers, but when value of i reaches to 3 then condition for inner if statement gets true and this will execute continue statement, which will force while loop to stop current iteration and start with next iteration, hence “3 ITVoyagers” is missing from output.

ITVoyagers

Example of continue statement with do-while loop

  #include<stdio.h>
void main()
{
int i=0;
do
{
i++;
if(i == 3)
{
continue;
}while(i<=5);
printf("%d ITVoyagers n",i);
}
}

 

Output:

  1 ITVoyagers
2 ITVoyagers
4 ITVoyagers
5 ITVoyagers
ITVoyagers

Example of continue statement with for loop

  #include<stdio.h>
void main()
{
int i;
for(i=0; i<=5; i++)
{
if(i == 3)
{
continue;
}
printf("%d ITVoyagers n",i);
}
}

Output:

  0 ITVoyagers
1 ITVoyagers
2 ITVoyagers
4 ITVoyagers
5 ITVoyagers
ITVoyagers

Try this practice quiz

CHECKOUT OTHER RELATED TOPICS

CHECKOUT OTHER QUIZZES

PRACTICALS IN C PROGRAM

We are aiming to explain all concepts of C in easiest terms as possible.
ITVoyagers-logo
ITVoyagers
Author

Leave a Comment