Pages

Saturday 1 May 2021

CONTROL STRUCTURES --Case control structures

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.

2)”Continue” Statement:

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

Programs in turboc3 : Files

File Handling in C File Handling concept in C language is used for store a data permanently in computer. Using this concept we can store our...