Break and Continue in C++
Break :
The break statement in C++ has the following two usage:
1. in loops
2. in switch - case
-
The break statement stops the current iteration of loop and exit.
- It can be use to terminate a case in switch.
Example :
#include< iostream > using namespace std; int main( ) { int i; for(i=1; i<10; i++) { if(i==4){ break; } cout<< i<<". Hello"<< endl; } return 0; }OUTPUT:
1. Hello 2. Hello 3. Hello
NOTE :
Break, only terminates the current loop in which it occurs.
Continue :
The continue statement stops the current iteration of loop and continue the next iteration.
Exmple :
#include< iostream > using namespace std; int main( ) { int i; for(i=1; i<10; i++) { if(i==4 || i==7){ continue; } cout<< i<<". Hello"<< endl; } return 0; }OUTPUT:
1. Hello 2. Hello 3. Hello 5. Hello 6. Hello 8. Hello 9. Hello
NOTE :
Continue, use only within loops.
Next topic is Function in C++
Training For College Campus
We offers college campus training for all streams like CS, IT, ECE, Mechanical, Civil etc. on different technologies
like
C, C++, Data Structure, Core Java, Advance Java, Struts Framework, Hibernate, Python, Android, Big-Data, Ebedded & Robotics etc.
Please mail your requirement at info@prowessapps.in
Projects For Students
Students can contact us for their projects on different technologies Core Java, Advance Java, Android etc.
Students can mail requirement at info@prowessapps.in