Break and continue statements
Break
On execution of “break” statement the control jumps out of the loop.
Syntax:
{
—-
—-
if (condition)
break;
—–
—–
}
The break statement can be used with for loop, while loop , do while loop and switch statement.
Continue
On execution of “continue” statement the control jumps to the beginning of the loop.
Syntax:
{
—-
—-
if (condition)
continue;
—–
—–
}
The continue statement can be used with for loop, while loop , do while loop.
Example of break statement with for loop
#include <stdio.h>
int main()
{
int i;
for(i=1;i<10;i++)
{
if(i>5)
break;
printf("%d\n",i);
}
return 0;
}
Output:
1 2 3 4 5
Example of break statement with while loop
#include <stdio.h>
int main()
{
int i=1;
while(i<=10)
{
if(i>5)
break;
printf("%d\n",i);
i++;
}
return 0;
}
Output:
1 2 3 4 5




