The sequential statement are executed one after the other but if the programmer wants to transfer the control from one point to some other point in the program the goto statement can be used during this statement control can be transferred from one statement to the specified statement without any condition.
Q.) W.A.P to print sum of 1 to 10
#include<stdio.h>
#include<conio.h>
void main()
{
int sum=0,i=0;
top:
if(i>10)
{
goto end;
}
sum=sum+i;
i++;
goto top;
end: printf(“%d”,sum);
getch();
}
Output
55