by Dinesh Thakur

 The goto statement is used not only in C but in other programming languages as well, primarily for moving back and forth in a given program. In a C program, the code lines are not numbered as is the case in some other programming languages. Therefore, for using goto statement one needs to put in a label, i.e., an identifier for the place of jump. At the starting point, i.e., point from where the jump is to be executed, we simply code as goto Label _identifier as illustrated below.

Statements;

goto Label_identifier //code at point of jump

statements;

Label_identifier : //code at destination of jump.

statements;

At the destination of the jump, the Label_identifier is put at the start of line. It is followed by a colon ( : ). The code statements may follow in the same line after the colon or in the next line. Program provides an illustration. In this, the label name is again.

#include<stdio.h>

#include<conio.h>
void main()
{
int i;
i=1;
again;
printf("%d",i);
i++;
if(i<10)
goto again;
getch();
}
 
OUTPUT:
 
1 2 3 4 5 6 7 8 9