Continue in C
continue skips the remaining statements of the current loop iteration and starts the next iteration.
Syntax / Basic Pattern
| for (…) { if (condition) continue; printf(“…”); } |
Easy points to remember
- continue does not end the loop.
- In a for loop, the update expression still runs.
- Use it to skip unwanted values while continuing the loop.
| ⭐ PRACTICE TIP: Type these programs yourself. Change the values and run them again. That is how control statements become easy. |
Program 1: Skip 3
| #include <stdio.h> int main(){for(int i=1;i<=5;i++){if(i==3)continue;printf(“%d “,i);}return 0;} |
| OUTPUT 1 2 4 5 |
Program 2: Print even
| #include <stdio.h> int main(){for(int i=1;i<=10;i++){if(i%2)continue;printf(“%d “,i);}return 0;} |
| OUTPUT 2 4 6 8 10 |
Program 3: Print odd
| #include <stdio.h> int main(){for(int i=1;i<=10;i++){if(i%2==0)continue;printf(“%d “,i);}return 0;} |
| OUTPUT 1 3 5 7 9 |
Program 4: Skip multiples of 3
| #include <stdio.h> int main(){for(int i=1;i<=10;i++){if(i%3==0)continue;printf(“%d “,i);}return 0;} |
| OUTPUT 1 2 4 5 7 8 10 |
Program 5: Positive values
| #include <stdio.h> int main(){int a[]={2,-1,4,-3,5};for(int i=0;i<5;i++){if(a[i]<0)continue;printf(“%d “,a[i]);}return 0;} |
| OUTPUT 2 4 5 |
Program 6: Skip zero
| #include <stdio.h> int main(){int a[]={2,0,4,0,6};for(int i=0;i<5;i++){if(a[i]==0)continue;printf(“%d “,a[i]);}return 0;} |
| OUTPUT 2 4 6 |
Program 7: Skip vowel
| #include <stdio.h> int main(){char s[]=”hello”;for(int i=0;s[i];i++){char c=s[i];if(c==’a’||c==’e’||c==’i’||c==’o’||c==’u’)continue;printf(“%c”,c);}return 0;} |
| OUTPUT hll |
Program 8: Skip 5
| #include <stdio.h> int main(){int i=0;while(i<7){i++;if(i==5)continue;printf(“%d “,i);}return 0;} |
| OUTPUT 1 2 3 4 6 7 |
Program 9: Multiples not 4
| #include <stdio.h> int main(){for(int i=1;i<=12;i++){if(i%4==0)continue;printf(“%d “,i);}return 0;} |
| OUTPUT 1 2 3 5 6 7 9 10 11 |
Program 10: Skip marks below 40
| #include <stdio.h> int main(){int a[]={35,55,42,28,70};for(int i=0;i<5;i++){if(a[i]<40)continue;printf(“%d “,a[i]);}return 0;} |
| OUTPUT 55 42 70 |
Program 11: Skip spaces
| #include <stdio.h> int main(){char s[]=”C language”;for(int i=0;s[i];i++){if(s[i]==’ ‘)continue;printf(“%c”,s[i]);}return 0;} |
| OUTPUT Clanguage |
Program 12: Skip odd squares
| #include <stdio.h> int main(){for(int i=1;i<=5;i++){if(i%2)continue;printf(“%d “,i*i);}return 0;} |
| OUTPUT 4 16 |
Program 13: Skip negative
| #include <stdio.h> int main(){for(int i=-3;i<=3;i++){if(i<0)continue;printf(“%d “,i);}return 0;} |
| OUTPUT 0 1 2 3 |
Program 14: Skip number 7
| #include <stdio.h> int main(){int i=1;while(i<=9){if(i==7){i++;continue;}printf(“%d “,i);i++;}return 0;} |
| OUTPUT 1 2 3 4 5 6 8 9 |
Program 15: Continue in nested loop
| #include <stdio.h> int main(){for(int i=1;i<=2;i++){for(int j=1;j<=3;j++){if(j==2)continue;printf(“%d%d “,i,j);}}return 0;} |
| OUTPUT 11 13 21 23 |
