The goto Keyword in C Language

The goto statement in C programming language is used for unconditional jump from one part of the program to another part of the program. It is always suggested not to use goto statement as this reduces the readability of the program. Using goto statement in C programming language is considered as poor programming approach.

The goto statement in C consists of two parts: label and goto keyword.

Example:

Output:
20

When goto label in C is encountered, control goes to the statement next to the label. Here, label is not the keyword. We can use any name for the label. It’s user defined.

You may also like...

14 Responses

  1. souvik says:

    what is the alternative approach then?

  2. fahad baig says:

    can we use conditions with goto ?
    like goto label if (a=10)
    ?

  3. Anonymous says:

    You should be able to use..

    if (a == 10){
    goto label;
    }

  4. Anonymous says:

    respected sir or madam would like to give another example using goto statement,to understand its usage clearly and properly.please.please.please.please reply at your earliest possible.

    • srikanth says:

      #include
      #include
      void main()
      {
      int i;
      label1:
      printf(“\n\n\t Enter the value of i:- “);
      scanf(“%d”,&i);
      if(i>0)
      {
      printf(“\n\n\t Thank you for positive value…,”);
      goto label2;
      }
      else
      {
      printf(“\n\n\t Only Positive Numbers Pls..,”);
      goto label1;
      }
      label2:
      printf(“\n\n\t World didn’t end here…,”);
      getch();
      }

  5. Anonymous says:

    what does these statements mean?

    #include
    #include

  6. Vishal says:

    #include are preprocessors
    means they contain predefined functions..which are later used in program:)

  7. Anonymous says:

    please give another example for using goto in more complex way..like loops in loops

  8. Anonymous says:

    #include are the preprocessors that will tell the compiler to include the text in the file STDIO.H before it executes its source code.

  9. LearnCOnline says:

    Thanks readers for your valuable comments.

    In addition, We have recently started a new forum.
    http://forum.learnconline.com/

    You can post your queries and get it resolved.

    Thanks,
    LearnCOnline.com

  10. Learning becomes easy here..thank you

  11. Anonymous says:

    ThaNk yew sooo mucH. This site iz very Helpful 4 us to leaRn moRe about C:)

  12. Anonymous says:

    great site

  13. Mahendra says:

    Sir, how to decide which text file should be include in pre-processor directive ?

Leave a Reply

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