Difference between break and continue in C

break:

The break statement is used in switch or loops.When the break statement is encountered ,it terminates the loop(for,while and do-while).It is used with decision making statement such as if...else.The break statement is also used with switch...case statement.
Syntax of break statement is:

 break;

Example:

#include<stdio.h>
int main(){
 int i;
 for(i=0;i<5;++i){
if(i==3)
break;   ////loop is terminated.
  printf(“%d “,i);
}
return 0;
}

Output: 0,1,2

continue:

The continue statement is used only in loops. When continue statement is encountered, all the statements next to it are skipped and the loop control goes to next iteration. 

Syntax of continue Statement is:
continue;

Example:

#include<stdio.h>
int main(){
int i;
for(i=0;i<5;++i){
if(i==3)
continue;
printf(“%d “,i);
}
return 0;
}
 

 Output: 0,1,2,4

Posted on by