The flow of execution is transferred from one
part of a program to another part without
carrying out any conditional test.
C supports
◦ break statement
◦ continue statement
◦ goto construct
break & continue Statements, goto
Constructs
• Format:
label:
{
statement;
}
.
.
.
goto label;
where label is an identifier and not a number.
In C programming, goto statement is used for altering the
normal sequence of program execution by transferring control
to some other part of the program.
The goto require a label in order to identify the place where the
branch is to be made
A label is any valid variable name and must be followed by a
colon
The label is placed immediately before the statement where to
control is to be transferred
The label: can be anywhere in the program either before or after
the goto label; statement.
goto breaks the normal sequential execution of
the program
Backward Jump: If the label: is before the
statement goto label; a loop will be formed and
some statements will be executed repeatedly
Forward Jump: if the label: is placed after the
goto label; some statement will be skipped
#include<stdio.h>
main()
{
int i=1;
bc:
if(i>5)
goto ab;
printf(“%d”,i);
i++;
goto bc;
ab:
{
printf(“%d’,i);
}
}
#include<stdio.h>
void main()
{
int a,sum=0,A;
printf("Enter a number");
A:
scanf("%d",&A);
if(A<=10)
{
sum=sum+A;
goto A;
}
printf("%d",sum);
}
#include<stdio.h>
void main()
{
int number;
printf(“ WWW. ");
goto x;
y:
printf(“ Expert");
goto z;
x:
printf("C Programming");
goto y;
z:
printf(".com");
}
#include<stdio.h>
#include<math.h>
main()
{
double x,y;
read:
scanf("%f", &x);
if (x < 0)
goto read;
y = sqrt(x);
printf("%f %f\n", x, y);
goto read;
}