Cheap VPS & Xen Server


Residential Proxy Network - Hourly & Monthly Packages

C goto


The goto statement is known as jump statement in C language. It is used to unconditionally jump to other label. It transfers control to other parts of the program.

It is rarely used today because it makes program less readable and complex.

Syntax:

  1. goto label;

goto example

Let’s see a simple example to use goto statement in C language.

  1. #include <stdio.h>
  2. #include <conio.h>
  3. void main() {
  4.   int age;
  5.   clrscr();
  6.    ineligible:
  7.    printf(“You are not eligible to vote!\n”);
  8.    printf(“Enter you age:\n”);
  9.    scanf(“%d”, &age);
  10.    if(age<18)
  11.         goto ineligible;
  12.    else
  13.         printf(“You are eligible to vote!\n”);
  14.    getch();
  15. }

Output:

You are not eligible to vote!
Enter you age:
11
You are not eligible to vote!
Enter you age:
44
You are eligible to vote!

Comments

comments