Break in c++


When we want exit from loop then we used break statemet in c. we can provide a specific condition if condition match then this exit from loop.


Simple example of Break in c++


#include<iostream>

using namespace std;

int main(){

int i;

clrscr();

for(i=1;i<=5;i++)

{

if(i==4)

{

break;

}

cout<<“Welcome %d\n”,i;

}

cout<<“Exit from loop here”;

return0

}



Output:
welcome 1
welcome 2
welcome 3
Exit from loop here