On Tuesday 13 December 2005 11:09 am, Jacob F. wrote:
I see no similarity. ‘goto’ is unstructured because the target point
is completely arbitrary; place a label in your code then jump right to
it. ‘break’ is completely structured; it’s part of the structure of
the enclosing loop and its target is defined by that structure.
Ahh – I found a reference. See
http://en.wikipedia.org/wiki/Structured_programming, and note Dijkstra’s
structured programming definition – every block of code has one entry
and one exit point. Break statements clearly violate the “one exit
rule. I was taught the Dijkstra definition at Santa Monica College.
That same page also lists a definition not demanding a single exit
allowing for break. I saw a lot of that when I left Santa Monica College
programmed in the real world. I also saw code that was horribly
break statements. More on that…
Break can improve readability on small loops, but on large loops
maintained by multiple people it can become a nightmare.
I agree with James; if the loop is long enough or complex enough for
these to be a problem, the body of the loop probably needs some
It absolutely does. Trouble is, in many shops loops start out 8 lines of
and over many, many years, maintenance programmers, many not
most not being privy to original design considerations, add features
by management on ultra-tight schedules. A few years later it’s 100 lines
code and the break statement is in the middle of it.
Under those circumstances, the once understandable break statement
the original programmer can result in unfathomable code, especially if
add more break statements.
What I’m saying isn’t as important today as it was 15 years ago, when
programs were not object oriented. Obviously, something like
easily be refactored just from its name. 15 years ago,
process_all_valid_incoming_paid_records() could not be.
By habit, I always think twice before using break or continue (redo in
If I still want to use it, then I go ahead.