1. break statement:
It is used to skip over a part of the code i.e. we can premature exit from a loop such as while, do-while, for or switch.
Syntax:
while (expression)
{
if (condition)
break;
}
Eg.
#include
using namespace std;
int main()
{
int i = 1;
while(i<10)
{
cout<<i<<endI;
if(i==5)
break;
i++;
}
}
The output is
1
2
3
4
5.
2. continue statement:
It by passes one iteration of the loop.
Syntax :
while (expression)
{
if (condition)
break;
}
Eg.
#include<iostream>
using namespace std;
int main()
{
int i = 0;
while(i<10)
{
i++;
if(i==5)continue;
cout<<i<<endI;
}
}
The output is
1
2
3
4
5
6
7
8
9
10