continue is a keyword.The continue statement can only be use within loop.On execution it transfers the control to the beginning of the loop,Thus ignoring the execution of all other statement written below it within the loop.A continue statement should always be dependent upon the condition.
Syntax of continue statement in for loop-:
for( _ ; _ ;_ )
{ _
_
if(condition)
continue;
else
_
_
}
Example of continue statement in for loop -:
ads #include<stdio.h>
#include<conio.h>
main()
{ int i=1;
for(i=1;i<=5;i++)
{ if(i==3)
continue;
else
printf(" %d \n ",i);
}
getch();
}
Output-: 1
2
4
5
Syntax of continue statement in while loop-:
while(condition)
{ _
_
if(condition)
continue;
else
_
_
}
Example of continue statement in while loop -:
#include<stdio.h>
#include<conio.h>
main()
{ int i=1;
while(i<=5)
{ if(i==3)
continue;
else
printf(" %d \n ",i);
i++;
}
getch();
}
Output-: 1
2
4
5
Syntax of continue statement in do-while loop-:
main()
{initialize;
do
{ _
_
if(condition)
continue;
else
_
_
}while(condition);
}
Example of continue statement in do-while loop -:
#include<stdio.h>
#include<conio.h>
main()
{ int i=1;
do
{ if(i==3)
continue;
else
printf(" %d \n ",i);
i++;
}while(i<=5);
getch();
}
Output-: 1
2
4
5
follow tech programiz
ReplyDelete