In this tutorial you will learn about difference between break and continue in C.
The break statement is used in switch or loops and continue statement is used only in loops. When break statement is encountered it immediately stops the switch or loop execution. When continue statement is encountered, all the statements next to it are skipped and the loop control goes to next iteration. Generally we use break and continue with some condition.
Below I have shared difference between break and continue statements along with an example in C.
Difference Between break a5knd continue in C
S.No. | break | continue |
1. | break statement is used in switch and loops. | continue statement is used in loops only. |
2. | When break is encountered the switch or loop execution is immediately stopped. | When continue is encountered, the statements after it are skipped and the loop control jump to next iteration. |
3. | Example:
#include<stdio.h> int main(){ int i; for(i=0;i<5;++i){ if(i==3) break; printf(“%d “,i); } return 0; }
Output: 0 1 2 |
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 |
If you have any doubts related to above difference between break and continue tutorial then feel free to ask it by commenting below.
very good
please published more about c++
hello sir, i want some help with one of the code i am working in C. Can you share your e mail address or something so that we can discuss about it?