Break and continue Statement
In C++, the break and continue statements are used to change the normal flow of loops such as for, while, or do-while loops. is encountered inside the loop, the loop is terminated and control is passed to the statement that follows the loop.
#include <iostream>
using namespace std;
int main() {
for (int i = 1; i <= 5; i++) {
if (i == 3) {
break;
}
cout << "i = " << i << endl;
}
cout << "Loop ended" << endl;
return 0;
}
Output:
i = 1
i = 2
Loop ended
Get Freelancing_Vibes’s stories in your inbox
Join Medium for free to get updates from this writer.
this example, when i is 3, the break statement is executed, terminating the loop.
continue Statement
The continue statement skips the current iteration of the loop and jumps to the next iteration.When a continue is encountered, the remaining code inside the loop is skipped for that iteration, and the loop proceeds to the next iteration.
#include <iostream>
using namespace std;
int main() {
for (int i = 1; i <= 5; i++) {
if (i == 3) {
continue;
}
cout << "i = " << i << endl;
}
return 0;
}
Output:
i = 1
i = 2
i = 4
i = 5
In this example, when i is 3, the continue statement is executed, causing the loop to skip the cout statement and proceed with the next iteration.







