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