break and continue are jump statements used to alter the flow of execution within loops and switch statements used In C programming.
break Statement:
The break statement is used to immediately terminate the innermost for, while, do-while loop, or switch statement.
#include<stdio.h>
main()
{
int i;
for(i=1;i<=100;++i)
{
if(i>=51)
break;
printf("\t%d",i);
}
}
main()
{
int i;
for(i=1;i<=100;++i)
{
if(i>=51)
break;
printf("\t%d",i);
}
}
Output
Ex.
continue Statement:
The continue statement is used to skip the remaining statements within the current iteration of a for, while, or do-while loop and proceed to the next iteration. It does not terminate the entire loop.
Ex.
#include<stdio.h>
main()
{
int i;
for(i=1;i<=100;++i)
{
if(i>=41 && i<=59)
continue;
printf("\t%d",i);
}
}
Output
main()
{
int i;
for(i=1;i<=100;++i)
{
if(i>=41 && i<=59)
continue;
printf("\t%d",i);
}
}
Output
No comments:
Post a Comment