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. General Programming
  3. C / C++ / MFC
  4. what's the point? do{...}while(FALSE);

what's the point? do{...}while(FALSE);

Scheduled Pinned Locked Moved C / C++ / MFC
question
15 Posts 8 Posters 0 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.
  • L Offline
    L Offline
    Like2Byte
    wrote on last edited by
    #1

    I've come across some code that is structured like this: do { //stuff... } while(FALSE); What's the difference between that and just doing the items that are in stuff WITHOUT the do-while(FALSE) "loop"?:confused:

    C L W 3 Replies Last reply
    0
    • L Like2Byte

      I've come across some code that is structured like this: do { //stuff... } while(FALSE); What's the difference between that and just doing the items that are in stuff WITHOUT the do-while(FALSE) "loop"?:confused:

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      The difference is that the above code is entitled to stand on the top position of the Coding Horrors forum.

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

      modified on Friday, February 8, 2008 3:06 PM

      L 1 Reply Last reply
      0
      • C CPallini

        The difference is that the above code is entitled to stand on the top position of the Coding Horrors forum.

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

        modified on Friday, February 8, 2008 3:06 PM

        L Offline
        L Offline
        led mike
        wrote on last edited by
        #3

        CPallini wrote:

        the Coding Orrors forum.

        What means "Coding Orros"? I know what Coding Oreos[^] are but never heard of Coding Orros.

        led mike

        E C 2 Replies Last reply
        0
        • L Like2Byte

          I've come across some code that is structured like this: do { //stuff... } while(FALSE); What's the difference between that and just doing the items that are in stuff WITHOUT the do-while(FALSE) "loop"?:confused:

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          Maybe they were trying to exercise the compilers optimization capabilities?

          led mike

          L 1 Reply Last reply
          0
          • L led mike

            Maybe they were trying to exercise the compilers optimization capabilities?

            led mike

            L Offline
            L Offline
            Like2Byte
            wrote on last edited by
            #5

            Just figured it out. Interspersed within the {..} are #define'd a macro (ESCAPEIF(returnvalue) calls. It's defined to 'break' if an error occurrs. At the end of the function is the cleanup thus: do { ret = foo(); //returns a '1' BREAKONERROR(ret); } WHILE(FALSE); //perform cleanup (ie: release memory where needed) Guess I should have followed the white rabbit a little more ..or took the bluepill.

            C 1 Reply Last reply
            0
            • L Like2Byte

              I've come across some code that is structured like this: do { //stuff... } while(FALSE); What's the difference between that and just doing the items that are in stuff WITHOUT the do-while(FALSE) "loop"?:confused:

              W Offline
              W Offline
              Waldermort
              wrote on last edited by
              #6

              It's better than using the ugly GOTO method. In a loop you have the option of using break and continue. In this case it's a loop to be run once, unless directed to do otherwise.

              Waldermort

              L N 2 Replies Last reply
              0
              • L led mike

                CPallini wrote:

                the Coding Orrors forum.

                What means "Coding Orros"? I know what Coding Oreos[^] are but never heard of Coding Orros.

                led mike

                E Offline
                E Offline
                El Corazon
                wrote on last edited by
                #7

                led mike wrote:

                What means "Coding Orros"?

                Coding Orros refers to members of a family tree: http://www.genealogytoday.com/surname/finder.mv?Surname=Orros[^] who are better at making pizza than coding. http://www.yellowbot.com/orros-pizza-grill-saint-johns-fl.html[^] although obvious to us, it was not obvious to them. After seeing the pizza examples in head-first-design-patterns, you begin to realize how they thought that any pizza maker is automatically a programmer. As you see, the results of pizza makers writing software is extra cheese in our code. :-D

                _________________________ Asu no koto o ieba, tenjo de nezumi ga warau. Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)

                1 Reply Last reply
                0
                • L led mike

                  CPallini wrote:

                  the Coding Orrors forum.

                  What means "Coding Orros"? I know what Coding Oreos[^] are but never heard of Coding Orros.

                  led mike

                  C Offline
                  C Offline
                  CPallini
                  wrote on last edited by
                  #8

                  And I even made it bold. :-O :sigh:

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                  L 1 Reply Last reply
                  0
                  • C CPallini

                    And I even made it bold. :-O :sigh:

                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                    L Offline
                    L Offline
                    led mike
                    wrote on last edited by
                    #9

                    CPallini wrote:

                    And I even made it bold.

                    I've always said "That Pallini is nothing if not bold"  :-D

                    led mike

                    1 Reply Last reply
                    0
                    • W Waldermort

                      It's better than using the ugly GOTO method. In a loop you have the option of using break and continue. In this case it's a loop to be run once, unless directed to do otherwise.

                      Waldermort

                      L Offline
                      L Offline
                      led mike
                      wrote on last edited by
                      #10

                      WalderM wrote:

                      It's better than using the ugly GOTO method.

                      better how? If you mean more readable I would argue that at best it is indistinguishably better.

                      led mike

                      1 Reply Last reply
                      0
                      • W Waldermort

                        It's better than using the ugly GOTO method. In a loop you have the option of using break and continue. In this case it's a loop to be run once, unless directed to do otherwise.

                        Waldermort

                        N Offline
                        N Offline
                        Nemanja Trifunovic
                        wrote on last edited by
                        #11

                        WalderMt's better than using the ugly GOTO method.

                        I agree that this code is most probably the replacement for goto, but dissagree that it is better. It is even worse, because it hides the intention.

                        Programming Blog utf8-cpp

                        1 Reply Last reply
                        0
                        • L Like2Byte

                          Just figured it out. Interspersed within the {..} are #define'd a macro (ESCAPEIF(returnvalue) calls. It's defined to 'break' if an error occurrs. At the end of the function is the cleanup thus: do { ret = foo(); //returns a '1' BREAKONERROR(ret); } WHILE(FALSE); //perform cleanup (ie: release memory where needed) Guess I should have followed the white rabbit a little more ..or took the bluepill.

                          C Offline
                          C Offline
                          CPallini
                          wrote on last edited by
                          #12

                          goto is better.

                          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                          B S 2 Replies Last reply
                          0
                          • C CPallini

                            goto is better.

                            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                            B Offline
                            B Offline
                            BadKarma
                            wrote on last edited by
                            #13

                            CPallini wrote:

                            goto is better.

                            Youre my HERO

                            codito ergo sum

                            1 Reply Last reply
                            0
                            • C CPallini

                              goto is better.

                              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                              S Offline
                              S Offline
                              Stephen Hewitt
                              wrote on last edited by
                              #14

                              goto is dangerous in C++ if care is not taken because jumping out of scope will NOT result in the destructors of any C++ objects in the scope.

                              Steve

                              C 1 Reply Last reply
                              0
                              • S Stephen Hewitt

                                goto is dangerous in C++ if care is not taken because jumping out of scope will NOT result in the destructors of any C++ objects in the scope.

                                Steve

                                C Offline
                                C Offline
                                CPallini
                                wrote on last edited by
                                #15

                                C++ has try-catch blocks, usually goto is not needed. :)

                                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                                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