OCJP

Jump Statement (goto) in C Language

C language supports jump statement like ‘goto’. You can conditionally jump to any line for execution in C Language using goto statement. You have to define the label where you want to jump.

...
en:  //it is label no ; here , you : is used 
..
..
goto en; //will jump to en:
#include<stdio.h>
#include<conio.h>
void main()
{
	int mark;
	clrscr();
	en:
	printf("\nEnter Mark :");
	scanf("%d",&mark);
	if(mark<0)
	{
		printf("\nInvalid Marks");
		goto en; //will jump to en:
	}
	printf("\nThank you");
	getch();
}

In above example you have to enter marks repeatedly until you do not enter positive marks. Jump Statement can be used in place of Loop also.

#include<stdio.h>
#include<conio.h>
void main()
{
int x=1;
clrscr();

label1:
printf("%d ",x);
x++;
if(x<=10)
{
goto label1:
}
getch();
}
//Output :1 2 3 4 5 6 7 8 9 10

Leave a Reply

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


× How can I help you?