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. Other Discussions
  3. The Weird and The Wonderful
  4. For loop horror

For loop horror

Scheduled Pinned Locked Moved The Weird and The Wonderful
29 Posts 25 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.
  • L Llasus

    I just spent an hour trying to think why the process didn't work. for(int nindex = MIN_VAL; nindex <= MAX_VAL; nindex++); { //50 lines of code that processes something } Maybe everyone has these kind of moments. :doh:

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

    Here, have one of these: :doh:

    cheers, Chris Maunder

    CodeProject.com : C++ MVP

    1 Reply Last reply
    0
    • L Llasus

      I just spent an hour trying to think why the process didn't work. for(int nindex = MIN_VAL; nindex <= MAX_VAL; nindex++); { //50 lines of code that processes something } Maybe everyone has these kind of moments. :doh:

      N Offline
      N Offline
      Nitron
      wrote on last edited by
      #9

      if it makes you feel any better, it took me about 5 mins of looking at it over and over again before i noticed what you were talking about :doh:

      ~Nitron.


      ññòòïðïðB A
      start

      C L A L 4 Replies Last reply
      0
      • M Marc Clifton

        Llasus wrote:

        Maybe everyone has these kind of moments.

        I had that exact moment about 15 years ago in a C++ app. It took me half the day trying to figure out why the loop executed once and only once. Marc

        Thyme In The Country
        Interacx
        My Blog

        C Offline
        C Offline
        Christopher Duncan
        wrote on last edited by
        #10

        Me, too. I think it's a rite of passage for C programmers. :doh:

        Christopher Duncan Author of The Career Programmer and Unite the Tribes Coming soon: Got a career question? Ask the Attack Chihuahua! www.PracticalUSA.com

        D 1 Reply Last reply
        0
        • C Christopher Duncan

          Me, too. I think it's a rite of passage for C programmers. :doh:

          Christopher Duncan Author of The Career Programmer and Unite the Tribes Coming soon: Got a career question? Ask the Attack Chihuahua! www.PracticalUSA.com

          D Offline
          D Offline
          Dan Neely
          wrote on last edited by
          #11

          Christopher Duncan wrote:

          Me, too. I think it's a rite of passage for C programmers.

          Yep right along with while (someBool = TRUE)

          -- If you view money as inherently evil, I view it as my duty to assist in making you more virtuous.

          1 Reply Last reply
          0
          • L Llasus

            I just spent an hour trying to think why the process didn't work. for(int nindex = MIN_VAL; nindex <= MAX_VAL; nindex++); { //50 lines of code that processes something } Maybe everyone has these kind of moments. :doh:

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

            Switch to a language that does not have loops (Haskell, for instance) and you won't have these problems any more :)


            Programming Blog utf8-cpp

            1 Reply Last reply
            0
            • C cp9876

              Luc Pattyn wrote:

              The compiler will help you

              Only the more recent ones - VC6 for example promoted the loop index to scope outside the loop.:)


              Peter "Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."

              J Offline
              J Offline
              jhwurmbach
              wrote on last edited by
              #13

              cp9876 wrote:

              VC6 for example promoted the loop index to scope outside the loop.

              That is one of many reasons why VC6 is regarded as extremely braindead... In fact it isn't a C++ compiler. Just a compiler that compiles a language looking a lot like C++...


              Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all.
              Douglas Adams, "Dirk Gently's Holistic Detective Agency"

              1 Reply Last reply
              0
              • L Llasus

                I just spent an hour trying to think why the process didn't work. for(int nindex = MIN_VAL; nindex <= MAX_VAL; nindex++); { //50 lines of code that processes something } Maybe everyone has these kind of moments. :doh:

                D Offline
                D Offline
                Dewm Solo
                wrote on last edited by
                #14

                Oh my god....and I was looking ....and looking....and looking.... The conditional statement was fine....and I couldn't find it at all....keep looking and reading all the comments here. Couldn't find it. I was about to give up and ask when BLAM!!!!! I saw it...there... That never happened to me. Luckily! I've done similar though and lost a good 3~4 hours of time trying to figure it out. I am actually surprised that this compiles though...and runs. Shouldn't the compiler complain about this?

                Dewm Solo - Managed C++ Developer

                J D 2 Replies Last reply
                0
                • L Llasus

                  I just spent an hour trying to think why the process didn't work. for(int nindex = MIN_VAL; nindex <= MAX_VAL; nindex++); { //50 lines of code that processes something } Maybe everyone has these kind of moments. :doh:

                  S Offline
                  S Offline
                  Simon Capewell
                  wrote on last edited by
                  #15

                  Dammit, I had to stick this in the IDE and debug it to work out what the hell was wrong with this. I think I've been doing a little too much ASP maintenance today :sigh:

                  1 Reply Last reply
                  0
                  • N Nitron

                    if it makes you feel any better, it took me about 5 mins of looking at it over and over again before i noticed what you were talking about :doh:

                    ~Nitron.


                    ññòòïðïðB A
                    start

                    C Offline
                    C Offline
                    Chris Losinger
                    wrote on last edited by
                    #16

                    same here

                    image processing toolkits | batch image processing

                    E 1 Reply Last reply
                    0
                    • C Chris Losinger

                      same here

                      image processing toolkits | batch image processing

                      E Offline
                      E Offline
                      emiaj
                      wrote on last edited by
                      #17

                      me too, then i saw it, the bug is on *beeeeeeeeep!* right there :)

                      T 1 Reply Last reply
                      0
                      • E emiaj

                        me too, then i saw it, the bug is on *beeeeeeeeep!* right there :)

                        T Offline
                        T Offline
                        Thea Ganoe
                        wrote on last edited by
                        #18

                        *beeeep* what's wrong...can't say "semicolon" ???

                        caridad

                        1 Reply Last reply
                        0
                        • D Dewm Solo

                          Oh my god....and I was looking ....and looking....and looking.... The conditional statement was fine....and I couldn't find it at all....keep looking and reading all the comments here. Couldn't find it. I was about to give up and ask when BLAM!!!!! I saw it...there... That never happened to me. Luckily! I've done similar though and lost a good 3~4 hours of time trying to figure it out. I am actually surprised that this compiles though...and runs. Shouldn't the compiler complain about this?

                          Dewm Solo - Managed C++ Developer

                          J Offline
                          J Offline
                          Jimmanuel
                          wrote on last edited by
                          #19

                          Dewm Solo wrote:

                          Shouldn't the compiler complain about this?

                          No, it's perfectly valid to stuff all of the loops processing into the ( ; ; ) of a for statement and create a loop with no explicitly defined code block. This has it's uses, but I always just enjoyed using it to obfuscate my code :)

                          1 Reply Last reply
                          0
                          • N Nitron

                            if it makes you feel any better, it took me about 5 mins of looking at it over and over again before i noticed what you were talking about :doh:

                            ~Nitron.


                            ññòòïðïðB A
                            start

                            L Offline
                            L Offline
                            Llasus
                            wrote on last edited by
                            #20

                            :laugh: nice one! actually it did! :laugh:

                            1 Reply Last reply
                            0
                            • S Stephen Hewitt

                              A classic C/C++ error; you haven't been coding long enough if you haven't run into this one before.

                              Steve

                              L Offline
                              L Offline
                              Llasus
                              wrote on last edited by
                              #21

                              I've been coding for about 5 years of my life. Maybe its more of the experience though. Since I haven't really encountered this until last time. :D

                              1 Reply Last reply
                              0
                              • N Nitron

                                if it makes you feel any better, it took me about 5 mins of looking at it over and over again before i noticed what you were talking about :doh:

                                ~Nitron.


                                ññòòïðïðB A
                                start

                                A Offline
                                A Offline
                                Andy Brummer
                                wrote on last edited by
                                #22

                                I didn't get it until Marc's comment about the body only running once.


                                This blanket smells like ham

                                1 Reply Last reply
                                0
                                • D Dewm Solo

                                  Oh my god....and I was looking ....and looking....and looking.... The conditional statement was fine....and I couldn't find it at all....keep looking and reading all the comments here. Couldn't find it. I was about to give up and ask when BLAM!!!!! I saw it...there... That never happened to me. Luckily! I've done similar though and lost a good 3~4 hours of time trying to figure it out. I am actually surprised that this compiles though...and runs. Shouldn't the compiler complain about this?

                                  Dewm Solo - Managed C++ Developer

                                  D Offline
                                  D Offline
                                  DavidNohejl
                                  wrote on last edited by
                                  #23

                                  Dewm Solo wrote:

                                  I am actually surprised that this compiles though...and runs. Shouldn't the compiler complain about this?

                                  Yeah. While it should of course compile, I'd want this warning: http://msdn2.microsoft.com/en-us/library/9x19t380(vs.80).aspx[^]


                                  [My Blog]
                                  "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn
                                  "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe

                                  D 1 Reply Last reply
                                  0
                                  • N Nitron

                                    if it makes you feel any better, it took me about 5 mins of looking at it over and over again before i noticed what you were talking about :doh:

                                    ~Nitron.


                                    ññòòïðïðB A
                                    start

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

                                    I had to look for help :)

                                    xacc.ide
                                    The rule of three: "The first time you notice something that might repeat, don't generalize it. The second time the situation occurs, develop in a similar fashion -- possibly even copy/paste -- but don't generalize yet. On the third time, look to generalize the approach."

                                    1 Reply Last reply
                                    0
                                    • D DavidNohejl

                                      Dewm Solo wrote:

                                      I am actually surprised that this compiles though...and runs. Shouldn't the compiler complain about this?

                                      Yeah. While it should of course compile, I'd want this warning: http://msdn2.microsoft.com/en-us/library/9x19t380(vs.80).aspx[^]


                                      [My Blog]
                                      "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn
                                      "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe

                                      D Offline
                                      D Offline
                                      Dewm Solo
                                      wrote on last edited by
                                      #25

                                      Indeed! Right on the button.

                                      Dewm Solo - Managed C++ Developer

                                      1 Reply Last reply
                                      0
                                      • L Llasus

                                        I just spent an hour trying to think why the process didn't work. for(int nindex = MIN_VAL; nindex <= MAX_VAL; nindex++); { //50 lines of code that processes something } Maybe everyone has these kind of moments. :doh:

                                        S Offline
                                        S Offline
                                        snorkie
                                        wrote on last edited by
                                        #26

                                        I was starting to get mad at this code, thinking it is one of those "inside" jokes where everybody laughs until you start laughing, then they laugh harder cause there is no joke. Nobody said what the problem was. Then after reading all the comments, I went back and reviewed it again. I found the issue! Funny how it never shows up till the end. Hogan

                                        L 1 Reply Last reply
                                        0
                                        • S snorkie

                                          I was starting to get mad at this code, thinking it is one of those "inside" jokes where everybody laughs until you start laughing, then they laugh harder cause there is no joke. Nobody said what the problem was. Then after reading all the comments, I went back and reviewed it again. I found the issue! Funny how it never shows up till the end. Hogan

                                          L Offline
                                          L Offline
                                          Llasus
                                          wrote on last edited by
                                          #27

                                          yes, just like the code when you encounter it. wasn't funny until you end up looking at it for 30 or so minutes and seeing that the semicolon was the problem. :D

                                          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