Do you even 'break' bro?!
-
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
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)
-
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
-
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)
-
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
I prefer to avoid a
break
in afor
loop, but that's the worst way to do it. :sigh: -
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
-
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
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.
-
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. 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) -
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
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
-
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. 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.
-
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.
-
DominicZA wrote:
cant seem to find the wall of shame
See that big TreeView on the left ...
Use the best guess
-
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. 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?) /raviMy new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
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!
Break
ing out of afor
loop is a code smell. (What's presented is even worse.) Maybe you don't want afor
loop at all. Or, quite possibly, you just need another condition.for ( int i = 0 ; i < MaxCols && i < dr.FieldCount ; i++ )
-
Break
ing out of afor
loop is a code smell. (What's presented is even worse.) Maybe you don't want afor
loop at all. Or, quite possibly, you just need another condition.for ( int i = 0 ; i < MaxCols && i < dr.FieldCount ; i++ )
-
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".
-
Break
ing out of afor
loop is a code smell. (What's presented is even worse.) Maybe you don't want afor
loop at all. Or, quite possibly, you just need another condition.for ( int i = 0 ; i < MaxCols && i < dr.FieldCount ; i++ )
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
-
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.
BobJanova wrote:
People are used to seeing a 'standard' loop
Show them more variety and they'll improve.