Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Most gratuitous use of 'goto'

Most gratuitous use of 'goto'

Scheduled Pinned Locked Moved The Lounge
question
32 Posts 23 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Chris Maunder

    What's the most gratuitous, inane, innappropriate or just plain wrong use of the goto keyword you've seen? cheers, Chris Maunder

    T Offline
    T Offline
    Tomas Petricek
    wrote on last edited by
    #3

    I once (many years ago) used goto to swap two lines in my basic code (something like this):

    goto a1
    a2:
    ' something in basic
    goto a3
    a1:
    ' something in basic
    goto a2
    a3:

    because on my laptop* didn't work Cut and Paste and this lines were to long :-D. Am I winner :) ?


    *) My laptop: 5MHz (10 with turbo) CPU; 1MB RAM; No harddisk; 640x200 display with two colors (yellow and blue):rolleyes: i'm only pointer to myself

    1 Reply Last reply
    0
    • C Chris Maunder

      What's the most gratuitous, inane, innappropriate or just plain wrong use of the goto keyword you've seen? cheers, Chris Maunder

      A Offline
      A Offline
      Alexander M
      wrote on last edited by
      #4

      wasnt this a non-coding forum!? :cool: Don't try it, just do it! ;-)

      C P 2 Replies Last reply
      0
      • C Chris Maunder

        What's the most gratuitous, inane, innappropriate or just plain wrong use of the goto keyword you've seen? cheers, Chris Maunder

        N Offline
        N Offline
        Navin
        wrote on last edited by
        #5

        I ran across some code where 'goto' was used to go to the end of a 'for' loop and do the next case. I think it's beause somebody didn't know about the continue statement. "When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity." - Albert Einstein

        T 1 Reply Last reply
        0
        • A Alexander M

          wasnt this a non-coding forum!? :cool: Don't try it, just do it! ;-)

          C Offline
          C Offline
          Chris Maunder
          wrote on last edited by
          #6

          I said "goto" not "coding". There's a difference :P cheers, Chris Maunder

          1 Reply Last reply
          0
          • N Navin

            I ran across some code where 'goto' was used to go to the end of a 'for' loop and do the next case. I think it's beause somebody didn't know about the continue statement. "When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity." - Albert Einstein

            T Offline
            T Offline
            Tim Ranker
            wrote on last edited by
            #7

            I have come across quite a few programmers that don't know about continue.

            F 1 Reply Last reply
            0
            • C Chris Maunder

              What's the most gratuitous, inane, innappropriate or just plain wrong use of the goto keyword you've seen? cheers, Chris Maunder

              S Offline
              S Offline
              Shog9 0
              wrote on last edited by
              #8

              Well, when i was very young, i wanted to stay up and watch TV all night, but my mom said "goto bed." I certainly felt that was inane, as well as just plain wrong. ;P

              Shog9

              I returned and saw under the sun, that the race is not to the swift, nor the battle to the strong...

              1 Reply Last reply
              0
              • C Chris Maunder

                What's the most gratuitous, inane, innappropriate or just plain wrong use of the goto keyword you've seen? cheers, Chris Maunder

                S Offline
                S Offline
                Stefan de Zeeuw
                wrote on last edited by
                #9

                Anyone on my team who dare's using goto is fired on the spot :mad:

                B 1 Reply Last reply
                0
                • C Chris Maunder

                  What's the most gratuitous, inane, innappropriate or just plain wrong use of the goto keyword you've seen? cheers, Chris Maunder

                  M Offline
                  M Offline
                  Marc Clifton
                  wrote on last edited by
                  #10

                  When my ex-wife said "goto he..!!!". Marc Latest AAL Article My blog Join my forum!

                  1 Reply Last reply
                  0
                  • C Chris Maunder

                    What's the most gratuitous, inane, innappropriate or just plain wrong use of the goto keyword you've seen? cheers, Chris Maunder

                    W Offline
                    W Offline
                    Wesner Moise
                    wrote on last edited by
                    #11

                    A number of years ago Microsoft published the DefWndProc source code, which is what you call from your WndProc after you have processed a windows message. I believe the function was over 3000 lines of code, although I have seen such long switches in Excel functions, too, but maybe not that long. There was a label called "ICantBelieveIUsedGoto" in the function, that went from one location of the function to another location. What I don't understand is why each case could have been broken out into a separate function, thus making it easier to maintain. Oh, yes, I remember, because this was windows 3.1. Thanks, Wes

                    1 Reply Last reply
                    0
                    • S Stefan de Zeeuw

                      Anyone on my team who dare's using goto is fired on the spot :mad:

                      B Offline
                      B Offline
                      bryce
                      wrote on last edited by
                      #12

                      are they allowed to use "continue" and "break" ? bryce --- Publitor, making Pubmed easy. http://www.sohocode.com/publitor

                      S 1 Reply Last reply
                      0
                      • B bryce

                        are they allowed to use "continue" and "break" ? bryce --- Publitor, making Pubmed easy. http://www.sohocode.com/publitor

                        S Offline
                        S Offline
                        Stefan de Zeeuw
                        wrote on last edited by
                        #13

                        I have been programming for 20+ years and never ever found any use for continue or break (except off course break in a switch statement), so to answer your question, no, they cannot. The same goes for the return statement. There can be only 1 entry point for a function and only 1 exit point. We always use a local var (result) to set the return value of a function. Using statements like goto, continue, break and return (the latter used in the wrong place) leads too often to "spaghetti code" IMHO.

                        B J J C P 6 Replies Last reply
                        0
                        • S Stefan de Zeeuw

                          I have been programming for 20+ years and never ever found any use for continue or break (except off course break in a switch statement), so to answer your question, no, they cannot. The same goes for the return statement. There can be only 1 entry point for a function and only 1 exit point. We always use a local var (result) to set the return value of a function. Using statements like goto, continue, break and return (the latter used in the wrong place) leads too often to "spaghetti code" IMHO.

                          B Offline
                          B Offline
                          bryce
                          wrote on last edited by
                          #14

                          as long as you're consistant :) i've heard people moan about the use of "goto" but they'll happily use break and continue... bit oxymoronic if you ask me :) Bryce --- Publitor, making Pubmed easy. http://www.sohocode.com/publitor

                          K 1 Reply Last reply
                          0
                          • S Stefan de Zeeuw

                            I have been programming for 20+ years and never ever found any use for continue or break (except off course break in a switch statement), so to answer your question, no, they cannot. The same goes for the return statement. There can be only 1 entry point for a function and only 1 exit point. We always use a local var (result) to set the return value of a function. Using statements like goto, continue, break and return (the latter used in the wrong place) leads too often to "spaghetti code" IMHO.

                            J Offline
                            J Offline
                            John M Drescher
                            wrote on last edited by
                            #15

                            I do use continue and break probably 1 time in every 10K lines of code I write. The multiple returns probably 1 in every 2K lines. I have not used a goto in several years so the ratio will probably be like 1 in every 250K lines I write... John

                            1 Reply Last reply
                            0
                            • S Stefan de Zeeuw

                              I have been programming for 20+ years and never ever found any use for continue or break (except off course break in a switch statement), so to answer your question, no, they cannot. The same goes for the return statement. There can be only 1 entry point for a function and only 1 exit point. We always use a local var (result) to set the return value of a function. Using statements like goto, continue, break and return (the latter used in the wrong place) leads too often to "spaghetti code" IMHO.

                              J Offline
                              J Offline
                              J Dunlap
                              wrote on last edited by
                              #16

                              There are definitely times when using continue, break, and return is actually better than not doing so. But when you find yourself needing to do it, it's important to ask yourself if there is a better way - breaking the function up into multiple functions, etc. If you say absolutely no gotos/continues/etc, occasionally you'll run into a place where in order to go by your rules you'll have to produce code that's more like 'spaghetti code' than if you allowed its use. * Believe me - I've seen this before (not very often, though). *Most of the cases were in complex string parsing functions.

                              "Blessed are the peacemakers, for they shall be called sons of God." - Jesus
                              "You must be the change you wish to see in the world." - Mahatma Gandhi

                              J 1 Reply Last reply
                              0
                              • J J Dunlap

                                There are definitely times when using continue, break, and return is actually better than not doing so. But when you find yourself needing to do it, it's important to ask yourself if there is a better way - breaking the function up into multiple functions, etc. If you say absolutely no gotos/continues/etc, occasionally you'll run into a place where in order to go by your rules you'll have to produce code that's more like 'spaghetti code' than if you allowed its use. * Believe me - I've seen this before (not very often, though). *Most of the cases were in complex string parsing functions.

                                "Blessed are the peacemakers, for they shall be called sons of God." - Jesus
                                "You must be the change you wish to see in the world." - Mahatma Gandhi

                                J Offline
                                J Offline
                                John M Drescher
                                wrote on last edited by
                                #17

                                jdunlap wrote: If you say absolutely no gotos/continues/etc, occasionally you'll run into a place where in order to go by your rules you'll have to produce code that's more like 'spaghetti code' than if you allowed its use. * Believe me - I've seen this before (not very often, though). These are the cases that I would use it. John

                                1 Reply Last reply
                                0
                                • C Chris Maunder

                                  What's the most gratuitous, inane, innappropriate or just plain wrong use of the goto keyword you've seen? cheers, Chris Maunder

                                  C Offline
                                  C Offline
                                  ColinDavies
                                  wrote on last edited by
                                  #18

                                  I for one actually don't know how to use 'goto' Nor do I understand why it is used. Regardz Colin J Davies

                                  *** WARNING *
                                  This could be addictive
                                  **The minion's version of "Catch :bob: "

                                  It's a real shame that people as stupid as you can work out how to use a computer. said by Christian Graus in the Soapbox

                                  1 Reply Last reply
                                  0
                                  • S Stefan de Zeeuw

                                    I have been programming for 20+ years and never ever found any use for continue or break (except off course break in a switch statement), so to answer your question, no, they cannot. The same goes for the return statement. There can be only 1 entry point for a function and only 1 exit point. We always use a local var (result) to set the return value of a function. Using statements like goto, continue, break and return (the latter used in the wrong place) leads too often to "spaghetti code" IMHO.

                                    C Offline
                                    C Offline
                                    ColinDavies
                                    wrote on last edited by
                                    #19

                                    AgedToPerfection wrote: (except off course break in a switch statement), I won't allow anyone to use sloppy switch statements in my projects. So I can't see the point of having a break at all. Regardz Colin J Davies

                                    *** WARNING *
                                    This could be addictive
                                    **The minion's version of "Catch :bob: "

                                    It's a real shame that people as stupid as you can work out how to use a computer. said by Christian Graus in the Soapbox

                                    1 Reply Last reply
                                    0
                                    • C Chris Maunder

                                      What's the most gratuitous, inane, innappropriate or just plain wrong use of the goto keyword you've seen? cheers, Chris Maunder

                                      J Offline
                                      J Offline
                                      Jack Puppy
                                      wrote on last edited by
                                      #20

                                      here: TRACE(_T("I love Code Project and me! hehe haha\n")); goto here; I think the only time I've ever used goto was for "cleanup" purposes within a function. I do remember coming across a Microsoft VC++ sample that used goto - if I'm not mistaken it was one of the multimedia samples.

                                      My 20 favorite films:
                                      http://www.ymdb.com/user_top20_view.asp?usersid=8912

                                      1 Reply Last reply
                                      0
                                      • T Tim Ranker

                                        I have come across quite a few programmers that don't know about continue.

                                        F Offline
                                        F Offline
                                        Frank Olorin Rizzi
                                        wrote on last edited by
                                        #21

                                        Tim Ranker wrote: I have come across quite a few programmers that don't know about continue. ..ehr... I continue to run into gotos... ...(double)ehr... F.O.R.

                                        1 Reply Last reply
                                        0
                                        • C Chris Maunder

                                          What's the most gratuitous, inane, innappropriate or just plain wrong use of the goto keyword you've seen? cheers, Chris Maunder

                                          F Offline
                                          F Offline
                                          Frank Olorin Rizzi
                                          wrote on last edited by
                                          #22

                                          ANd now, for something completely different... I am currently contemplating sticking a *bunch* of gotos in my next component. It's C, it's an authentication component, and therefore its logic is something like: IF (bad user id) { error=BAD_ID; skip the rest except the last piece; } IF (bad PSW) { error=BAD_PSW; skip the rest except the last piece; } ... last piece: record to log file/DB what happened; return Success/Failure So.. a *big bunch* of nested if's, or a *big bunch* of if-else's, or a *big bunch* of gotos Aside, if no-one notices, I'm sure tempteds to use the gotos just 'cause ! I'd stop only if it would lead to the problems I hit in Assembly, when the label is too far, but I have never seen that problem in C/C++. Geee... they gave use a goto statement... let's use when appropriate ! F.O.R.

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups