What is C unconditional jump statements?

CServer Side ProgrammingProgramming

C programming language allows jumping from one statement to another. It also supports break, continue, return and go to jump statements.

break

  • It is a keyword which is used to terminate the loop (or) exit from the block.
  • The control jumps to next statement after the loop (or) block.
  • break is used with for, while, do-while and switch statement.
  • When break is used in nested loops then, only the innermost loop is terminated.

The syntax for break statement is as follows −

Example

Following is the C program for break statement −

 Live Demo

#include<stdio.h>
main( ){
   int i;
   for (i=1; i<=5; i++){
      printf ("%d", i);
      if (i==3)
      break;
   }
}

Output

When the above program is executed, it produces the following output −

1 2 3

continue

The syntax for the continue statement is as follows −

Example

Following is the C program for the continue statement −

#include<stdio.h>
main( ){
   int i;
   for (i=1; i<=5; i++){
      if (i==2)
      continue;
      printf("%d", i)
   }
}

Output

When the above program is executed, it produces the following output −

1 2 3 4 5

return

It terminates the execution of function and returns the control of calling function

The syntax for return statement is as follows −

return[expression/value];

Example

Following is the C program for the return statement −

 Live Demo

#include<stdio.h>
main(){
   int a,b,c;
   printf("enter a and b value:");
   scanf("%d%d",&a,&b);
   c=a*b;
   return(c);
}

Output

When the above program is executed, it produces the following output −

enter a and b value:2 4
Process returned 8 (0x8)

goto

It is used after the normal sequence of program execution by transferring the control to some other part of program.

The syntax for the goto statement is as follows −

Example

Following is the C program for the goto statement −

 Live Demo

#include<stdio.h>
main( ) {
   printf("Hello");
   goto l1;
   printf("How are");
   l1: printf("you");
}

Output

When the above program is executed, it produces the following output −

Hello you
raja
Published on 25-Mar-2021 07:18:02
Advertisements