void goto()

This is a discussion on void goto() within the C++ Programming forums, part of the General Programming Boards category; I have seen it before. How do I use it? Also, what is the code to use it?...

  1. #1
    BubbleMan
    Guest

    Question void goto()

    I have seen it before. How do I use it? Also, what is the code to use it?

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    3
    I don't know about a void goto(), but there is (At least in Microsoft Visual C++ 6.0), a keyword function goto. It's fairly simle to use, just put in any word/number/whatever at the beginning of a line of code, with a : after it. And the command goto (whatever you used); will take you back to that line.
    Example:

    #include <iostream.h>

    int main()
    {
    int a = 0;
    here:cout << a;
    goto here;
    }

  3. #3
    Registered User ski6ski's Avatar
    Join Date
    Aug 2001
    Posts
    133
    Alot of people will tell you to "Avoid goto".
    In my opinion, i used goto in the past, but will not use it now due to if/else or do/while loops.
    That is my oppinion though.
    C++ Is Powerful
    I use C++
    There fore I am Powerful

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    79
    Most people say goto produces "spaghetti-code" that is hard to read and that it should be avoided.
    There is still one occasion where it might be good though:
    if you have several while and for loops nested into each other and you want to get out of them all, using breaks would be quite tedious, but a simple goto could would make it simple:

    while(something) {
    //stuff
    for (whatever) {
    //stuff
    while (blabla) {
    // stuff
    while (anything) {
    if (breakcondition)
    goto end;
    }
    }
    }
    }
    end:

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  2. saying hello and 1st question
    By darksys in forum C Programming
    Replies: 12
    Last Post: 10-31-2008, 02:58 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. Just one Question?
    By Irish-Slasher in forum C++ Programming
    Replies: 6
    Last Post: 02-12-2002, 09:19 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21