Break and Continue:
There are two statement built in C ,break; and continue;
to interrupt the normal flow of control of a program. Loop perform a set of
operation repeatedly until certain
condition becomes false but, it is
sometimes desirable to skip some statement inside loop and terminate the loop
immediately without checking the test
expression.
In such cases, break and continue statements are used.
Break:
In C programming , break is used in terminating the loop
immediately after it is encountered.
The break statement is used with conditional if
statement. The break statement can be used in terminating all three loops for,
while ,do-while loops.
Syntax break:
Break;
|
Program to understand break statement.
#include<stdio.h>
main()
{
int n;
for(n=1;n<=5;n++)
{
if(n==3)
break;
printf(“number:%d\n”,n);
}
}
|
Continue:
It is sometimes desirable
to skip some statements inside the loop. In such cases, continue statements are
used.
Just like break , continue
is also used with conditional if statement.
Syntax for continue:
Continue;
|
Program to understand
continue statement
#include<stdio.h>
Main()
{
Int n;
For(n=1;n<=5;n++)
{
If(n==3)
Continue;
Printf(“number:%d\n”,n);
}
}
|
No comments:
Post a Comment