Goto Statement in C Programming

It is a well known as ‘jumping statement in c.’ It is primarily used to transfer the control of execution to any place in a program. It is useful to provide branching within a loop.

When the loops are deeply nested at that if an error occurs then it is difficult to get exited from such loops. Simple break statement cannot work here properly. In this situations, goto statement is used.

Syntax :

	goto [expr];

Figure :

Program :

/*  Program to demonstrate goto statement.
Creation Date : 09 Nov 2010 08:14:00 PM
Author : www.technoexam.com [Technowell, Sangli] */

#include <stdio.h>
#include <conio.h>

int main(void)
{
	int i=1, j;
	clrscr();
	while(i<=3)
	{
		for(j=1; j<=3; j++)
		{
			printf(" * ");
			if(j==2)
			goto stop;
		}
		i = i + 1;
	}
	stop:
		printf("\n\n Exited !");
	getch();
	return 0;
}

Output :


 *  *

 Exited_

Leave A Comment

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