Jump Statements

Jump Statements :

Jump Statements are used to move the program control within a function.

goto statement :

  • It can transfer control anywhere in the same function of a program.
  • The target destination of a goto statement is marked by a label.
  • A label and goto must appear inthe same function.

Syntax :

goto label;
:
:
label :

e.g.

a=0;
start:
printf(“n%d”,++a);
if(a<50)
goto start;

  • A label must not immediately precede a closing brace.
  • A goto statement may not jump forward over a variable definition.It is only possible only if the variable definition is occuring in a block and the entire block is jumped.

break statement :

  •  It is used to skip over a part of a code or loop.
  •  It can be used to terminate while, do-while, for and switch statements.
  •  It immediately skips the rest of the loop and jumps over to the statement following the loop

e.g.

int a=34;
while(1)
{
if(a>10)
–a;
else
break;
}

continue statement :

  •  It is used to skip over the next statements of a loop and perform the next iteration.
  •  It must not be confused with break which takes you out of the loop wheres continue skips its following code in loop and performs next iteration.

e.g.

int a,b;
while(1)
{
printf(“ENter two numbers”);
scanf(“%d%d”,&a,&b);
if(b==0)
{
printf(“n Denominator can’t be zero”);
continue;
}
int c=a/b;
printf(“n Division=%d”,c);
break;
}

return statement :

  • It can be used to return value to calling code from the function and to immediate exit from the function to its caller function.
  • A function may contain several return statement but only one of them should be executed.

Leave a Reply

Your email address will not be published. Required fields are marked *