break; statement helps in coming out of the current loop
Further in case of nested loop it gets you out of the innermost loop.
// program to print the value of i
#include <iostream>
using namespace std;
int main() {
for (int i = 1; i <= 5; i++) {
// break condition
if (i == 3) {
break;
}
cout << i << endl;
}
return 0;
}
/*Q;Design a program to print the employee IDs starting
from 1 until an Id occur who have resigned. IDs of
resigned persons are 7 and 10 .*/
#include<iostream>
using namespace std;
int main()
{
int meet=0;
for(int i=1;i<30;i++)
{
if(i==7||i==10)
break;
else
meet=1;
cout<<"Employee ID:"<<i<<endl;
}
return 0;
}