goto Statement in C
The goto statement is used to unconditionally transfer the control to any location within the program whose address in the form of label follows the statement. It should be noted that break and continue statements transfer control to a fixed location; after loop body in case of break and to the condition of the while loop or counter-modification statement of for loop in case of continue. However, goto can transfer control to any location. Program 1 shows how to display a multiplication table of any number entered by a user using goto statement.
#include <stdio.h>
void main()
{
int number, count, mul;
printf(“Please enter the number? ”);
scanf(“%d”, &number);
count = 1;
myLoop: /* Label for if statement*/
if (count <= 10)
{
mul = number * count;
printf(“\n%d x %d = %d”,
number, count, mul);
count ++;
goto myLoop;
}
}
Program 1: Program to display multiplication table of a number using goto statement.