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;
}
1 2 3 4 5 6 7 8 9 10
#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;
}
Second case