Jumping statement break and continue in c with example
Jumping statement: (break and continue) in C
❖ Jumping statement: (break and continue)
➢ C break : The break is a keyword in C which is used to bring the program control
out of the loop. The break statement is used inside loops or switch statement. The
break statement breaks the loop one by one, i.e., in the case of nested loops, it
breaks the inner loop first and then proceeds to outer loops. The break statement
in C can be used in the following two scenarios:
1. With switch case
2. With
loopIts syntax
is:
break;
The break statement is almost always used with if…else statement inside the loop.
➢ Example of break Statement :
#include
#includevoid main ()
{
int i; clrscr();
for(i = 0; i
loop
#include void main
()
{ int i = 0;
clrscr();
while(1)
{
printf(“%d
“,i);i++;
if(i == 10)
break;
}
printf(“came out of while loop”);
}
➢ C continue : The continue statement in C language is used to bring the program
control to the beginning of the loop. The continue statement skips some lines of
codeinside the loop and continues with the next iteration. It is mainly used for a
conditionso that we can skip some code for a particular condition.
➢ Its syntax is:
➢ continue;
The continue statement is almost always used with the if…else statement.
➢ How continue statement works?
➢ Continue statement example1
Page 2
Jumping statement: (break and continue) in C
#include
#includevoid main()
{ int i=1;//initializing a local
variable clrscr();
//starting a loop from 1
to 10for(i=1;i
#includevoid main()
{ int k = 0; clrscr();
while( k !=10)
{
printf(“%d”,
k);continue;
k++;
}
Output:
1
2
3
4
6
7
8
9
10
getch();
}
Output:
infinite loop
(Press
ctrl+Break)
Page 3
…