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

goto loops

Scheduled Pinned Locked Moved The Lounge
csharpquestion
88 Posts 45 Posters 7 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.
  • realJSOPR realJSOP

    Wow - looks like someone didn't agree with you, and didn't say why.

    .45 ACP - because shooting twice is just silly
    -----
    "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
    -----
    "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

    M Offline
    M Offline
    moon_stick
    wrote on last edited by
    #24

    It's not something I'm going to lose any sleep over!

    Sarchasm : The gulf between the author of sarcastic wit and the person who doesn't get it.

    J 1 Reply Last reply
    0
    • L Lost User

      This article/blog[^] Shows situations where goto statements can be used to greater effect than other soloutions although I must confess I can see better ways to code some of the examples, that the author ignores. I was always taught to avoid goto's at all costs and have always stuck to this advice, however, like you, I have noticed collegues use them a lot.

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #25

      Funny how no-one even the comments could come up with a really good alternative (I agree for simplicity, the && is approach is best). How would I do it?

      bool Do(params Func<bool>[] args)
      {
      foreach (var a in args)
      if (!a())
      return false;
      return true;
      }
      ...

      if (Do(Step1, Step2, Step3, Step4, Step5, Step6, Step7))
      Console.WriteLine("Brillant!");

      xacc.ide
      IronScheme - 1.0 RC 1 - out now!
      ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

      R S 2 Replies Last reply
      0
      • realJSOPR realJSOP

        Lucian-aSterX wrote:

        i give up.

        Why? You're not French...

        .45 ACP - because shooting twice is just silly
        -----
        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
        -----
        "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

        R Offline
        R Offline
        Rage
        wrote on last edited by
        #26

        We did not give up. We made a tactical counter march and just never had any strategic opportunity to go back to the front.

        1 Reply Last reply
        0
        • L leppie

          Funny how no-one even the comments could come up with a really good alternative (I agree for simplicity, the && is approach is best). How would I do it?

          bool Do(params Func<bool>[] args)
          {
          foreach (var a in args)
          if (!a())
          return false;
          return true;
          }
          ...

          if (Do(Step1, Step2, Step3, Step4, Step5, Step6, Step7))
          Console.WriteLine("Brillant!");

          xacc.ide
          IronScheme - 1.0 RC 1 - out now!
          ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

          R Offline
          R Offline
          Rage
          wrote on last edited by
          #27

          I was thinking about a similar construction with function pointers, but I know no C#. This is a very cool solution.

          1 Reply Last reply
          0
          • M moon_stick

            It's not something I'm going to lose any sleep over!

            Sarchasm : The gulf between the author of sarcastic wit and the person who doesn't get it.

            J Offline
            J Offline
            Johnny J
            wrote on last edited by
            #28

            Wasn't me even though I don't agree with you. But since you are so dead set I'm wrong, I challenge you: Show me ONE piece of code where a GoTo has a meaningful use!

            T P M 3 Replies Last reply
            0
            • realJSOPR realJSOP

              Wow - looks like someone didn't agree with you, and didn't say why.

              .45 ACP - because shooting twice is just silly
              -----
              "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
              -----
              "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

              P Offline
              P Offline
              Peter Mulholland
              wrote on last edited by
              #29

              :laugh:

              Pete

              1 Reply Last reply
              0
              • realJSOPR realJSOP

                No serious programmer uses a goto. EDIT (After the 1 vote)---------------- Okay - maybe we all do - when we goto the bathroom...

                .45 ACP - because shooting twice is just silly
                -----
                "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                -----
                "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

                modified on Monday, July 5, 2010 10:22 AM

                J Offline
                J Offline
                Johnny J
                wrote on last edited by
                #30

                Strange - when I post a comment along those lines, I get downvoted, but when you do it gets upvoted. Makes me think that some people here go more for the person than the message! Isn't the first time I have noticed that, though...

                P T R realJSOPR 4 Replies Last reply
                0
                • J Johnny J

                  Wasn't me even though I don't agree with you. But since you are so dead set I'm wrong, I challenge you: Show me ONE piece of code where a GoTo has a meaningful use!

                  T Offline
                  T Offline
                  Tom Deketelaere
                  wrote on last edited by
                  #31

                  Now your just setting him up to post code in the lounge and getting him flamed for doing so. I'm on to you ;P

                  1 Reply Last reply
                  0
                  • realJSOPR realJSOP

                    No serious programmer uses a goto. EDIT (After the 1 vote)---------------- Okay - maybe we all do - when we goto the bathroom...

                    .45 ACP - because shooting twice is just silly
                    -----
                    "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                    -----
                    "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

                    modified on Monday, July 5, 2010 10:22 AM

                    P Offline
                    P Offline
                    Pete OHanlon
                    wrote on last edited by
                    #32

                    John Simmons / outlaw programmer wrote:

                    No serious programmer uses a goto.

                    The whimsical ones do though :-D

                    "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                    As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                    My blog | My articles | MoXAML PowerToys | Onyx

                    1 Reply Last reply
                    0
                    • J Johnny J

                      Strange - when I post a comment along those lines, I get downvoted, but when you do it gets upvoted. Makes me think that some people here go more for the person than the message! Isn't the first time I have noticed that, though...

                      P Offline
                      P Offline
                      Pete OHanlon
                      wrote on last edited by
                      #33

                      You earn your upvote rights by scaring people. ;)

                      "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                      As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                      My blog | My articles | MoXAML PowerToys | Onyx

                      1 Reply Last reply
                      0
                      • J Johnny J

                        Wasn't me even though I don't agree with you. But since you are so dead set I'm wrong, I challenge you: Show me ONE piece of code where a GoTo has a meaningful use!

                        P Offline
                        P Offline
                        Pete OHanlon
                        wrote on last edited by
                        #34

                        10 Print "This Code is useless."
                        20 Goto 10

                        "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                        As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                        My blog | My articles | MoXAML PowerToys | Onyx

                        J 1 Reply Last reply
                        0
                        • J Johnny J

                          Strange - when I post a comment along those lines, I get downvoted, but when you do it gets upvoted. Makes me think that some people here go more for the person than the message! Isn't the first time I have noticed that, though...

                          T Offline
                          T Offline
                          Tom Deketelaere
                          wrote on last edited by
                          #35

                          Well if you must know I up voted him for the remark about the 1 vote and the goto the bathroom part. Could be that my sense of humor is a bit off today but I thought it was funny so...

                          1 Reply Last reply
                          0
                          • P Pete OHanlon

                            10 Print "This Code is useless."
                            20 Goto 10

                            "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                            As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                            My blog | My articles | MoXAML PowerToys | Onyx

                            J Offline
                            J Offline
                            Johnny J
                            wrote on last edited by
                            #36

                            Very meaningful! I guess you got me there... ;P

                            1 Reply Last reply
                            0
                            • J Johnny J

                              Strange - when I post a comment along those lines, I get downvoted, but when you do it gets upvoted. Makes me think that some people here go more for the person than the message! Isn't the first time I have noticed that, though...

                              R Offline
                              R Offline
                              Rage
                              wrote on last edited by
                              #37

                              Well, he has a .45 in reach. Makes everybody agree with you.

                              A 1 Reply Last reply
                              0
                              • J Johnny J

                                Strange - when I post a comment along those lines, I get downvoted, but when you do it gets upvoted. Makes me think that some people here go more for the person than the message! Isn't the first time I have noticed that, though...

                                realJSOPR Offline
                                realJSOPR Offline
                                realJSOP
                                wrote on last edited by
                                #38

                                I got 1-voted, and probably from the same person that 1-voted you. I edited it because I thought that's why I was 1-voted - I had neglected to mention the one valid goto everyone uses. Of course, the 1-voters can also goto hell for all I care.

                                .45 ACP - because shooting twice is just silly
                                -----
                                "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                                -----
                                "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

                                J R 2 Replies Last reply
                                0
                                • realJSOPR realJSOP

                                  I got 1-voted, and probably from the same person that 1-voted you. I edited it because I thought that's why I was 1-voted - I had neglected to mention the one valid goto everyone uses. Of course, the 1-voters can also goto hell for all I care.

                                  .45 ACP - because shooting twice is just silly
                                  -----
                                  "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                                  -----
                                  "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

                                  J Offline
                                  J Offline
                                  Johnny J
                                  wrote on last edited by
                                  #39

                                  5 for that...

                                  1 Reply Last reply
                                  0
                                  • realJSOPR realJSOP

                                    I got 1-voted, and probably from the same person that 1-voted you. I edited it because I thought that's why I was 1-voted - I had neglected to mention the one valid goto everyone uses. Of course, the 1-voters can also goto hell for all I care.

                                    .45 ACP - because shooting twice is just silly
                                    -----
                                    "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                                    -----
                                    "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

                                    R Offline
                                    R Offline
                                    Rage
                                    wrote on last edited by
                                    #40

                                    John Simmons / outlaw programmer wrote:

                                    goto hell

                                    Hell ?[^]

                                    C 1 Reply Last reply
                                    0
                                    • J Johnny J

                                      Wasn't me even though I don't agree with you. But since you are so dead set I'm wrong, I challenge you: Show me ONE piece of code where a GoTo has a meaningful use!

                                      M Offline
                                      M Offline
                                      moon_stick
                                      wrote on last edited by
                                      #41

                                      I think the nested 'for' loop example is meaningful enough: for (int i = 0; i < I_BOUND; i++) { for (int j = 0; j < J_BOUND; j++) { if (MyTestingFunction(i, j, k)) { goto LoopExit; } } } LoopExit: Steve McConnell gives a few other examples here[^]. To be clear, I'm not saying there aren't other ways of doing this (as there clearly are), and I don't believe there are any situations where using a goto provides funtionality above and beyond other native constructs (though am willing to be proved wrong!). I just don't agree that you can categorically state that use of goto is *always* wrong.

                                      Sarchasm : The gulf between the author of sarcastic wit and the person who doesn't get it.

                                      J 1 Reply Last reply
                                      0
                                      • M moon_stick

                                        I think the nested 'for' loop example is meaningful enough: for (int i = 0; i < I_BOUND; i++) { for (int j = 0; j < J_BOUND; j++) { if (MyTestingFunction(i, j, k)) { goto LoopExit; } } } LoopExit: Steve McConnell gives a few other examples here[^]. To be clear, I'm not saying there aren't other ways of doing this (as there clearly are), and I don't believe there are any situations where using a goto provides funtionality above and beyond other native constructs (though am willing to be proved wrong!). I just don't agree that you can categorically state that use of goto is *always* wrong.

                                        Sarchasm : The gulf between the author of sarcastic wit and the person who doesn't get it.

                                        J Offline
                                        J Offline
                                        Johnny J
                                        wrote on last edited by
                                        #42

                                        It's probably easier, but I still don't think it's a good use in this case. Sort of like exiting a room through the window. I'm not an expert on this, but can you be sure that jumping out of a nested loop like that doesn't leave something not cleaned up properly, stack e.g.?

                                        M L 2 Replies Last reply
                                        0
                                        • J Johnny J

                                          It's probably easier, but I still don't think it's a good use in this case. Sort of like exiting a room through the window. I'm not an expert on this, but can you be sure that jumping out of a nested loop like that doesn't leave something not cleaned up properly, stack e.g.?

                                          M Offline
                                          M Offline
                                          moon_stick
                                          wrote on last edited by
                                          #43

                                          It depends on the context - if MyTestingFunction() is expensive to run then an intelligent way to exit the loop early is a pretty good reason, especially if the bounds of the data structure being traversed are very large. The variables in the loops are scoped by the braces so by the time the exit label is hit, the variables are out of scope and the GC can do its thing. Assuming that MyTestingFunction() is stateless and isn't dealing with unmanaged resources, I don't believe there's a memory leak issue here.

                                          Sarchasm : The gulf between the author of sarcastic wit and the person who doesn't get it.

                                          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