TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

C continue statement

C continue statement with programming examples for beginners and professionals. Example of continue statement in c, C continue statement with inner loop, covering concepts, control statements, c array, c pointers, c structures, c union, c strings and more.

<< Back to C

C continue statement

The continue statement in C language is used to bring the program control to the beginning of the loop. The continue statement skips some lines of code inside the loop and continues with the next iteration. It is mainly used for a condition so that we can skip some code for a particular condition.

Syntax:

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

Continue statement example 1

#include<stdio.h>
void main ()
{
	int i = 0; 
	while(i!=10)
	{
		printf("%d", i); 
		continue; 
		i++;
	}
}

Output

infinite loop

Continue statement example 2

#include
int main(){
int i=1;//initializing a local variable     
//starting a loop from 1 to 10  
for(i=1;i<=10;i++){    
if(i==5){//if value of i is equal to 5, it will continue the loop  
continue;  
}  
printf("%d \n",i);  
}//end of for loop  
return 0;
}  

Output

1
2
3
4
6
7
8
9
10

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

C continue statement with inner loop

In such case, C continue statement continues only inner loop, but not outer loop.

#include
int main(){
int i=1,j=1;//initializing a local variable  
for(i=1;i<=3;i++){    
for(j=1;j<=3;j++){  
if(i==2 && j==2){  
continue;//will continue loop of j only  
}  
printf("%d %d\n",i,j);  
}  
}//end of for loop  
return 0;
}  

Output

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

As you can see, 2 2 is not printed on the console because inner loop is continued at i==2 and j==2.


Next TopicC goto statement


Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf