Continue Statement

The Continue statement is used inside loops.Continue statement skips some lines of code inside the loop and continues with next iteration.Continue statement are mainly used for those condition we can skip some code for a particular condition.

Syntax :

//loop statements
continue;
//some lines of the code which is skipped

Let’s see the example of continue statement

#include<stdio.h>  
int main(){  
int i=11;         
for(i=11;i<=20;i++){      
if(i==15){
//if value of i is equal to 15, it will continue the loop    
continue;    
}    
printf("%d \n",i);    
}   
return 0;  
}

Output

11
12
13
14
16
17
18
19
20

As you can see, 15 is not printed on the console because loop is continued at i==15.

Continue Statement with inner loop:

In C language continue statement continues only inner loop but not outer loop.Let’s see the example of continue

Statement with inner loop

#include<stdio.h>  
int main(){  
int i=1,j=1;    
for(i=1;i<=3;i++){      
for(j=1;j<=3;j++){    
if(i==2 && j==2){    
continue;    
}    
printf("%d %d\n",i,j);    
}    
}    
return 0;  
}

Output

1 1
1 2
1 3
2 1
2 3
3 1
3 2
3 3

Submit your review
1
2
3
4
5
Submit
     
Cancel

Create your own review

The Technical Funda
Average rating:  
 0 reviews