Goto statement in C

goto is a keyword as well as jumping statement. goto is use to transfer the control or jump.

goto statement always required label.

Syntax of goto statement:

	
    abc: ← colun
    
    ↑
    label_name with colun 
    

Goto with label use in two ways

Syntax:

1. backword declaration


	label_name:
    - - - -  -
     -- - - - 
     goto label_name;
    

Syntax:

2. forward declaration


	goto label_name;
    - - - -  -
     -- - - - 
     label_name:
    

Example of goto statement.


	#include<stdio.h>

	void main()
	{
		int a;
		clrscr();
		raza:
		printf("You are not eligible for driving license.");

		printf("\nEnter Your Age:- ");
		scanf("%d",&a);
		if(a<18)
		{
			goto raza;
		}
		else
		{
			printf("Your are eligible for driving license.");
		}
		getch();
	}

Output:


	You are not eligible for driving license.
	Enter Your Age:- 12
	You are not eligible for driving license.
	Enter Your Age:- 26
	Your are eligible for driving license.

Post Your Comment