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, continue statement:- It bypasses one iteration of the loop.
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.
while (expression)
if (condition) break;
}
Eg.
#include<iostream>
using namespace std;
int main()
{
int i=1;
while(i<10)
{
cout<<i<<endl;
if(i==5)
break;
i++;
}
}
The output is
1
2
3
4
5
continue statement: It bypasses 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<<endl;
}
}
The output is
1
2
3
4
5
6
7
8
9
10