Break and Continue in C++
Break and Continue in C++
Break Statement in C++
The break statement in c++ is used to break loop and switch statement. Breaks statement used to breaks the current flow of the program at the given condition. The break statement in C++ terminates the loop when it is meet unexpectedly.
It is also use in switch case control structure after the case blocks
Syntax of break statement
break;
Program of break statement in C++
#include <iostream> using namespace std; int main() { for (int i = 1; i <= 10; i++) { if (i == 5) { break; } cout<<i<<"\n"; } }
Output
1 2 3 4
Continue Statement in C++
The continue statement in C++ is used to continue the loop. Continue statement is used to continues the current iteration of the program and skips the remaining code at certain condition and control the program goes to next iterarion. It is used to move to the next iteration.