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. Do you even 'break' bro?!

Do you even 'break' bro?!

Scheduled Pinned Locked Moved The Lounge
htmltutorialquestion
23 Posts 16 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.
  • R Ravi Bhavnani

    loctrice wrote:

    "You never break from a loop"

    That's nonsense. /ravi

    My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

    OriginalGriffO Offline
    OriginalGriffO Offline
    OriginalGriff
    wrote on last edited by
    #7

    You're forgetting the old maxim: "Those who can, do; those who can't, teach" There is nowhere where this is more apposite than in university computer education. :sigh: If you wish proof of this, just visit QA...:suss: (My apologies to any good teachers out there: you do know you are in a teeny, tiny minority, right?)

    The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)

    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

    J 1 Reply Last reply
    0
    • D DominicZA

      So...I havent been on here in a while, but I cant seem to find the wall of shame so I thought here would do :P While going through our current framework I came across a module written by one of our senior devs, who apparently doesnt know what a break is, here is an example of what he does :

      for (var i = 0;i < myArray.length; i++) {
      if (conditionIsMet) {
      i = myArray.length;
      }
      }

      I gave him the benefit of the doubt and thought that maybe he was using i somewhere else, but he wasn't. Anyways, just a little laugh...Has anyone else found any gems like this??

      -- Dom

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #8

      It would appear that many schools are teaching that you should always obfuscate your control flow with crazy "I'm going to avoid using this keyword at all costs"-constructs.

      1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        You're forgetting the old maxim: "Those who can, do; those who can't, teach" There is nowhere where this is more apposite than in university computer education. :sigh: If you wish proof of this, just visit QA...:suss: (My apologies to any good teachers out there: you do know you are in a teeny, tiny minority, right?)

        The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)

        J Offline
        J Offline
        jim lahey
        wrote on last edited by
        #9

        Had I listened to college and university tutors in in 2001 I'd have learnt COBOL as "nothing is as good for manipulating text files".

        G 1 Reply Last reply
        0
        • D DominicZA

          So...I havent been on here in a while, but I cant seem to find the wall of shame so I thought here would do :P While going through our current framework I came across a module written by one of our senior devs, who apparently doesnt know what a break is, here is an example of what he does :

          for (var i = 0;i < myArray.length; i++) {
          if (conditionIsMet) {
          i = myArray.length;
          }
          }

          I gave him the benefit of the doubt and thought that maybe he was using i somewhere else, but he wasn't. Anyways, just a little laugh...Has anyone else found any gems like this??

          -- Dom

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #10

          I prefer to avoid a break in a for loop, but that's the worst way to do it. :sigh:

          1 Reply Last reply
          0
          • D DominicZA

            So...I havent been on here in a while, but I cant seem to find the wall of shame so I thought here would do :P While going through our current framework I came across a module written by one of our senior devs, who apparently doesnt know what a break is, here is an example of what he does :

            for (var i = 0;i < myArray.length; i++) {
            if (conditionIsMet) {
            i = myArray.length;
            }
            }

            I gave him the benefit of the doubt and thought that maybe he was using i somewhere else, but he wasn't. Anyways, just a little laugh...Has anyone else found any gems like this??

            -- Dom

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #11

            DominicZA wrote:

            cant seem to find the wall of shame

            See that big TreeView on the left ...

            Use the best guess

            B 1 Reply Last reply
            0
            • L loctrice

              In school I was taught that it was very wrong to break out of a loop. It wasn't just taught, there were 2 commandments students had to live by. One had to do with goto , the other was "You never break from a loop". You could get points off your project for that, or possibly a bad grade. What you posted is exactly what I learned, however with some instructors you could get away with adding a compound condition to the for loop. Of coarse in the real world you can break :cool:

              If it moves, compile it

              A Offline
              A Offline
              AlphaDeltaTheta
              wrote on last edited by
              #12

              Now I realize that what was taught (and is been too) is sheer elephanting nonsense X| X| X|

              Beauty cannot be defined by abscissas and ordinates; neither are circles and ellipses created by their geometrical formulas.

              ~ Carl von Clausewitz ~

              Source

              1 Reply Last reply
              0
              • V V 0

                In school we learned never ever to use break, continue or goto (only exception is break in switch statements). If we had to break we were told to develop a construct like you mention here. Similar for return statements (only allowed for each method). This one however I support. You were downgraded if you didn't obey this rule.

                V.
                (MQOTD Rules and previous Solutions )

                L Offline
                L Offline
                lewax00
                wrote on last edited by
                #13

                V. wrote:

                In school we learned never ever to use break, continue or goto (only exception is break in switch statements). If we had to break we were told to develop a construct like you mention here.

                Wow, that's crazy. Not using break is wasteful, if you know you're done with the loop you should just get out of it, and it's not like it's unclear where it goes. continue I can kind of get, you could just reorganize your code in most cases (since probably 99.99% of the time it's already in a condition, and that condition could be flipped). It really sounds like your teachers heard "don't use goto" and decided that included any instruction that directly created a jump :doh: (minus structures like conditionals and loops)

                1 Reply Last reply
                0
                • D DominicZA

                  So...I havent been on here in a while, but I cant seem to find the wall of shame so I thought here would do :P While going through our current framework I came across a module written by one of our senior devs, who apparently doesnt know what a break is, here is an example of what he does :

                  for (var i = 0;i < myArray.length; i++) {
                  if (conditionIsMet) {
                  i = myArray.length;
                  }
                  }

                  I gave him the benefit of the doubt and thought that maybe he was using i somewhere else, but he wasn't. Anyways, just a little laugh...Has anyone else found any gems like this??

                  -- Dom

                  E Offline
                  E Offline
                  Ennis Ray Lynch Jr
                  wrote on last edited by
                  #14

                  I am speculating that those who were taught to never use break in school had a prof. (who are we kidding, an adjust faculty member) who grew up with VB where breaks and exits litter the landscape like reflective markers on a roadway. Avoiding spaghetti logic is important, avoiding breaks not so much. I had a great VB6 example of how not to use breaks but I can't find it. Rule of thumb 1 break per loop is ok, more than 1 is not.

                  Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. "And they, since they Were not the one dead, turned to their affairs" -- Robert Frost "All users always want Excel" --Ennis Lynch

                  1 Reply Last reply
                  0
                  • V V 0

                    In school we learned never ever to use break, continue or goto (only exception is break in switch statements). If we had to break we were told to develop a construct like you mention here. Similar for return statements (only allowed for each method). This one however I support. You were downgraded if you didn't obey this rule.

                    V.
                    (MQOTD Rules and previous Solutions )

                    A Offline
                    A Offline
                    AlphaDeltaTheta
                    wrote on last edited by
                    #15

                    V. wrote:

                    You were downgraded if you didn't obey this rule.

                    We didn't have grades but marks, -15 :sigh:

                    Beauty cannot be defined by abscissas and ordinates; neither are circles and ellipses created by their geometrical formulas.

                    ~ Carl von Clausewitz ~

                    Source

                    1 Reply Last reply
                    0
                    • V V 0

                      In school we learned never ever to use break, continue or goto (only exception is break in switch statements). If we had to break we were told to develop a construct like you mention here. Similar for return statements (only allowed for each method). This one however I support. You were downgraded if you didn't obey this rule.

                      V.
                      (MQOTD Rules and previous Solutions )

                      B Offline
                      B Offline
                      BobJanova
                      wrote on last edited by
                      #16

                      What the actual elephant. A for loop with a conditional break is a standard idiom for finding things in collections ... never mind permitted, it's a standard pattern!

                      P 1 Reply Last reply
                      0
                      • L Lost User

                        DominicZA wrote:

                        cant seem to find the wall of shame

                        See that big TreeView on the left ...

                        Use the best guess

                        B Offline
                        B Offline
                        BobJanova
                        wrote on last edited by
                        #17

                        To be fair it isn't called that any more and the new name is really un-obvious.

                        1 Reply Last reply
                        0
                        • V V 0

                          In school we learned never ever to use break, continue or goto (only exception is break in switch statements). If we had to break we were told to develop a construct like you mention here. Similar for return statements (only allowed for each method). This one however I support. You were downgraded if you didn't obey this rule.

                          V.
                          (MQOTD Rules and previous Solutions )

                          R Offline
                          R Offline
                          Ravi Bhavnani
                          wrote on last edited by
                          #18

                          V. wrote:

                          In school we learned never ever to use ... goto

                          And did your instructors explain why it was unwise to use a goto?  (Was Dijkstra's paper ever discussed in class?) /ravi

                          My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                          1 Reply Last reply
                          0
                          • B BobJanova

                            What the actual elephant. A for loop with a conditional break is a standard idiom for finding things in collections ... never mind permitted, it's a standard pattern!

                            P Offline
                            P Offline
                            PIEBALDconsult
                            wrote on last edited by
                            #19

                            Breaking out of a for loop is a code smell. (What's presented is even worse.) Maybe you don't want a for loop at all. Or, quite possibly, you just need another condition. for ( int i = 0 ; i < MaxCols && i < dr.FieldCount ; i++ )

                            B Y 2 Replies Last reply
                            0
                            • P PIEBALDconsult

                              Breaking out of a for loop is a code smell. (What's presented is even worse.) Maybe you don't want a for loop at all. Or, quite possibly, you just need another condition. for ( int i = 0 ; i < MaxCols && i < dr.FieldCount ; i++ )

                              B Offline
                              B Offline
                              BobJanova
                              wrote on last edited by
                              #20

                              Conditions in the for loop itself are much less clear, to me at least. People are used to seeing a 'standard' loop and might well miss that entirely.

                              P 1 Reply Last reply
                              0
                              • J jim lahey

                                Had I listened to college and university tutors in in 2001 I'd have learnt COBOL as "nothing is as good for manipulating text files".

                                G Offline
                                G Offline
                                Gary Wheeler
                                wrote on last edited by
                                #21

                                jim lahey wrote:

                                COBOL as "nothing is as good for manipulating text files".

                                I just everted my upper gastrointestinal tract. The ejecta (formerly my lunch) achieved an appreciable fraction of c[^] as it punched through the roof of our building.

                                Software Zen: delete this;

                                1 Reply Last reply
                                0
                                • P PIEBALDconsult

                                  Breaking out of a for loop is a code smell. (What's presented is even worse.) Maybe you don't want a for loop at all. Or, quite possibly, you just need another condition. for ( int i = 0 ; i < MaxCols && i < dr.FieldCount ; i++ )

                                  Y Offline
                                  Y Offline
                                  Yuriy Loginov
                                  wrote on last edited by
                                  #22

                                  I personally prefer using the method you suggested as it is the cleanest looking and preserves the loop invariant. Breaking half way through the loop means you don't properly finish the iteration and raises the question of why did you actually start the next iteration if there was no need to do it. Its like going to the store to get a loaf of bread and then realizing half way that you already have bread at home and then turning back

                                  1 Reply Last reply
                                  0
                                  • B BobJanova

                                    Conditions in the for loop itself are much less clear, to me at least. People are used to seeing a 'standard' loop and might well miss that entirely.

                                    P Offline
                                    P Offline
                                    PIEBALDconsult
                                    wrote on last edited by
                                    #23

                                    BobJanova wrote:

                                    People are used to seeing a 'standard' loop

                                    Show them more variety and they'll improve.

                                    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