Thread: goto()

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    9

    Question goto()

    ok, everyone is telling me to use the goto() command, but every time I try it doesnt work. Can someone please explain how the goto() command works and what I do to make it work?

    Thx

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Do you mean the keyword goto (as in jump to another part of the program), or some screen positioning function to move the cursor to a point on the screen?

    > but every time I try it doesnt work
    Posting an example might help
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    goto needs a label like in basic.

    #include <iostream.h>

    void main()
    {
    cout << "\ntest";

    goto label2;

    label1:
    cout << "\nlabel 1";

    goto end;

    label2:
    cout << "\nlabel 2";

    goto label1;

    end:

    cout << "\ndone.";
    }

    gotoxy(y,x) sets the x,y coords in the display.

    Borland

    #include <stdio.h>
    #include <conio.h>

    void main()
    {
    gotoxy(5,12), printf("row 12, col 5");

    }

    or is it col 12, row 5 hmmm

    VC old versions

    #include <graph.h>
    #include <stdio.h>

    void main()
    {
    _settextposition(5,12), printf(" row 5, col 12");
    }
    Last edited by ronin; 10-26-2001 at 01:46 PM.
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  4. #4
    Barjor
    Guest
    Who is telling you to use GoTo? As a rule of thumb GoTo should NEVER be used. I strongly suggest that you change the design if you "need" to use the GoTo statement

  5. #5
    Bobish
    Guest
    GOTO is EVIL it is the the #1 way to get messy code

  6. #6
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    I never use goto; I always use functions. I was merely answering the question.
    Last edited by ronin; 10-26-2001 at 10:24 PM.
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  7. #7
    Registered User ski6ski's Avatar
    Join Date
    Aug 2001
    Posts
    133
    Search the Windows and Game boards for goto and see what comes up. I know that you will find some interesting stuff.....I have been there.
    C++ Is Powerful
    I use C++
    There fore I am Powerful

  8. #8
    In The Light
    Join Date
    Oct 2001
    Posts
    598

    goto or not goto

    i'm teaching myself this C++ thing out of books and the like.
    one guy says "avoid goto in al cases" the next says "it's there use it"
    in the book C++ The Programing Language, on pg 137 Stroustrup says "The goto has few uses in general high-level programing..."
    i think i'll stay away from it, if for any other reason to avoid the aperance of ignorance.
    mr

  9. #9
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    goto is still the best way to exit from deeply nested loops. Its part of the language whether you like it or not. Unconditional jumps are common at assembler level yet no one moans about that!
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  10. #10
    In The Light
    Join Date
    Oct 2001
    Posts
    598
    Stroustrup refers to the assembler using goto.


    -------------------------------------------------------------

    looks like your "free the weed" wishes are going well in the UK

  11. #11
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    Right on bro!!!

    BUT downgrading cannabis to class c does not make it legal it just means you cant get arrested for possession of small amounts..... Exactly what is a small amount? I think the cops will still confiscate it ( and smoke it themselves if they are the coppers I know) if you are searched and they find it on you. Still at least its a small step in the right direction.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  12. #12
    Registered User
    Join Date
    Oct 2001
    Posts
    95
    goto isn't a function, and it does need a label.
    Think out of the box! Open Source rules!

    -Breach23

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, 12:32 PM
  3. Does goto have a glitch or...?
    By Blackroot in forum C++ Programming
    Replies: 9
    Last Post: 02-18-2006, 10: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