Break statement in C++ by R4R Team

Break statement in C++ :
-It is statement which break the line and come outside the scope of the loop or anything.
-Basically, break statement is only work in loops and switch cases in C++

Break statement in Loops:

program:

#include < iostream>
using namespace std;
int main()
{
int i=1;
while(i)
{
cout<< i<<" ";
//when i will become 10 then loop break
if(i==10)
{
break;
}
i++;

}
return 0;
}


output-

1 2 3 4 5 6 7 8 9 10


Break statement in switch case:

program:

#include < iostream>
using namespace std;
int main()
{
int i=2;
switch(i)
{
case 1:
cout<<"First case";
break;
case 2:
cout<<"Second case";
break;
case 3:
cout<<"Third case";
break;
}
return 0;
}


output-

Second case




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!