goto help?

This is a discussion on goto help? within the C++ Programming forums, part of the General Programming Boards category; I need help with the goto function. whenever i set a label and click goto, it goes to that one...and ...

  1. #1
    Registered User Zenomori's Avatar
    Join Date
    Apr 2005
    Location
    Hinesville, GA
    Posts
    3

    goto help?

    I need help with the goto function. whenever i set a label and click goto, it goes to that one...and only that one. if i put another label and set a goto and the name of that label as goto, it goes to the first ( here is an example).
    Staraws: cout << "Hello" << endl;
    goto Starasw;

    JWRW: cout << "testing" << endl;
    goto JWRW ( it goes to the first one though)

    Here is the source code for my project if that will help.
    Attached Files Attached Files

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    I can't think of an explanation for this behavior, but I would suggest a round about solution that solves another design flaw: don't use goto.

    Goto is often looked down upon in C/C++ circles, as these higher-level language have developed much better control structures than goto. Although goto does sometimes have a purpose - it's almost never the best option. I would strongly recommend you redesign your program flow to use functions and loops, etc...

  3. #3
    Registered User Zenomori's Avatar
    Join Date
    Apr 2005
    Location
    Hinesville, GA
    Posts
    3

    Wink

    oops, this was a problem on my part ( and a really stupid mistake).
    Next time i'll try harder to solve a problem before whining about it.

  4. #4
    Registered User
    Join Date
    May 2005
    Posts
    6
    I think I've used goto one time. It was to bypass some text getting sent to stdout.

    Code:
    if(suchcode == something){Goto NullOut;}
        printf("%d\n", suchcode);
    
    NullOut:
        ;;
    Then again whatever it was only got used for debug purposes, and really didn't need to be there anyway. You're better off with calling a function than getting confused later on (if you program grows in size) with all of the labels that you have created, etc.

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Quote Originally Posted by Wolve
    I think I've used goto one time. It was to bypass some text getting sent to stdout.

    Code:
    if(suchcode == something){Goto NullOut;}
        printf("%d\n", suchcode);
    
    NullOut:
        ;;
    Why not
    Code:
    if(suchcode != something)
      printf("%d\n", suchcode);
    Same affect.

    Goto is one of those things that if you have to ask if you should use it then you shouldn't use it.

  6. #6
    Registered User
    Join Date
    May 2005
    Posts
    6
    My point exactly lol

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. temperature sensors
    By danko in forum C Programming
    Replies: 22
    Last Post: 07-10-2007, 07:26 PM
  2. goto command
    By jhwebster1 in forum C Programming
    Replies: 3
    Last Post: 02-21-2006, 11:32 AM
  3. Does goto have a glitch or...?
    By Blackroot in forum C++ Programming
    Replies: 9
    Last Post: 02-18-2006, 09:40 AM
  4. helpppp
    By The Brain in forum C Programming
    Replies: 1
    Last Post: 07-27-2005, 07:05 PM
  5. Need some help with a basic tic tac toe game
    By darkshadow in forum C Programming
    Replies: 1
    Last Post: 05-12-2002, 04:21 PM

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