1)”Break”
Statement:
When a break statement appears in a loop or in switch control structure. A break statement inside the body of a loop breaks completely out of the loop no more instructions in the body of the loop are executed. It can be used within for, while, switch statements. The break statement can be written as ‘ break; ’ without any expression (or) statements.
The continue statement just skips any statement after it on that iteration of the loop. The current iteration of the loop is terminated and the loop statement is executed again, as if the last instruction of the loop body has been reached. The continue statement is written as ‘continue;‘ without any expression (or) statement.
Write a ‘C’ program to illustrate “continue” statement.
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i;
clrscr();
printf(“enter any number: “);
scanf(“%d”,&n);
for(i=1;i<=10;i++)
{
if(n==i)
continue;
else
printf(“%d”,i);
}
getch();
}
Output- enter any number: 5
1 2 3 4 6 7 8 9 10
3)”Goto” statement:
These statements are classified into two types. They are,
1. Forward jump.
2. Backward jump.
Write a ‘C’ program to illustrate Forward jump.
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf(“Start of the program”);
goto label;
label:
printf(“\n Entered into the inside label”);
printf(“\n End of the program”);
getch();
}
Output:
Start of the program
Entered into the inside label
End of the program
Write a ‘C’ program to illustrate Backward jump:
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf(“\nStart of the program”);
label:
printf(“\n I am inside of the label”);
goto label;
printf(“\n End of the program”);
getch();
}
Output:
I am inside of the label will be printed infinite times
No comments:
Post a Comment