Thread: void goto()

  1. #1

    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
    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.

    #include <iostream.h>

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

  3. #3
    Registered User ski6ski's Avatar
    Join Date
    Aug 2001
    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
    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) {
    for (whatever) {
    while (blabla) {
    // stuff
    while (anything) {
    if (breakcondition)
    goto 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, 03: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
    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, 10:19 AM