Header Ads Widget

Break and Continue statement in C

 Break:-

            A break statement is used to exit from enclosing loop or switch block. During execution of a program  , whenever a break statement is encountered inside a loop or switch block it takes the control of execution out from the loop or switch block and jumps to the immediate next statement after the loop or switch block.

Example:-

#include<stdio.h>
int main()
{
int i;
for(i=1;i<=10;i++)
{
if(i==6)
break;
printf("%d\n",i);
}
return 0;
}

Output:-

1
2
3
4
5

Continue:-

                 During the execution of the program whenever a continue statement is encountered it causes to skip the execution of subsequent statement in loop and begins the next iteration of the loop.

Example:-

#include<stdio.h>
int main()
{
int i;
for(i=1;i<=10;i++)
{
if(i==6)
continue;
printf("%d\n",i);
}
return 0;
}

Output:-

1
2
3
4
5 // 6 will not printed here
7
8
9
10


<<Pre - Nested loop in C                                      Next - Practice questions on loop>>






Recommended Post:

Hackerearth Problems:-

Hackerrank Problems:-
Data structure:-

Key points:-

 MCQs:-