Unlike break statement,which is used to jump the control out of the loop,it is sometimes required to skip some part of the loop and to continue the execution
with next loop iteration.Continue statement used inside the loop helps to bypass the section of a loop and passes the control to the beginning of the loop to continue the execution with the next loop iteration.The syntax is follows :
continue;
Example
Write a program to print the first 20 natural numbers skipping the number divisible by 5.
#include<stdio.h>
main()
{
int i;
for(i=1;i<=20;i++)
{
if((i%5)==0)
continue;
printf("%d",i);
}
}
OUTPUT
1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19
with next loop iteration.Continue statement used inside the loop helps to bypass the section of a loop and passes the control to the beginning of the loop to continue the execution with the next loop iteration.The syntax is follows :
continue;
Example
Write a program to print the first 20 natural numbers skipping the number divisible by 5.
#include<stdio.h>
main()
{
int i;
for(i=1;i<=20;i++)
{
if((i%5)==0)
continue;
printf("%d",i);
}
}
OUTPUT
1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19
0 comments:
Post a Comment