I had recently read in a book that using the break statement in say e.g. for loops is considered inelegant (although it is widely accepted for use in the switch statement).
What is the reason for this “accusation”?
Should I use a break statement in a for loop, or should I use multiple conditions?
You’ll have to ask the author of the book (which book?), since my ESP is on the fritz today[citation needed].
Sometimes[when?] it’s said that, if you write lots of
breakstatements throughout your code body, then it’s no longer easy to see the loop invariants and the control flow without performing a detailed program analysis.But, realistically, a couple of
breakstatements inside conditional blocks isn’t going to hurt anyone, and complicating loop conditionals is, IMO, more immediately prone to going horribly wrong.