CodesandTutorials
Home   Programming   Hardware   Networking
 
Next generation website theme is here (black, neon and white color) - Reduces eye strain and headache problems.  

C Categories

Goto Statement

« Previous Point - Continue Statement Next Chapter - Operators »

Description

Goto statement is mainly used when program becomes large and unreadable for the user. And also to pass the control from one location of the program to another.

Syntax

goto label;
//statements
label:
// code

Source code


  • //Using goto statement
  • #include <stdio.h>
  • #include <conio.h>
  • void main()
  • {
  • 	int dividend,divisor,quotient,remainder;
  • 	char ch;
  • 	clrscr();
  • 	do
  • 	{
  • 		printf("Enter dividend : ");
  • 		scanf("%d", & dividend);
  • 		printf("Enter divisor : ");
  • 		scanf("%d",&divisor);
  •        		if(divisor==0)
  • 	            {
  • 		             goto input;
  • 		}
  • 		quotient=divident/divisor;
  • 		remainder=divident%divisor;
  • 		printf("Quotient is : %d ,",quotient);
  • 		printf("Remainder is : %d",remainder);
  • 		printf("\nDo you want to do another calculation? (y/n)");
  • 		scanf("%c",&ch);
  • 	}while(ch!='n');
  •    input:
  •    printf("Invalid divisor entered, quiting the program");
  • 	getch();
  • }

Program working steps

  • This program is similar to previous continue statement program. The difference is in the statement used, here we have just used goto statement thats it.
  • When goto input statement on line no.17 is executed, then the program control jumps to the line no.26 and prints the statement 'Invalid divisor entered, quiting the program'.

« Previous Point - Continue Statement Next Chapter - Operators »

Tip Box

Goto statement are rarely used in the program because it is difficult to debug and understand.


Advertisement

Rate Website
   

 


Terms of Use | Privacy Policy | Contact Us
CodesandTutorials © 2014 All Rights Reserved