Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

17
  • 7
    Depends on what the condition in particular is. Commented Feb 27, 2018 at 13:44
  • 4
    There is a reason why misra forbid use of "break" and "continue" within loops. See also this: stackoverflow.com/q/3922599/476681 Commented Feb 27, 2018 at 14:26
  • 35
    I think the number of lines itself is not the real issue. It could be written on one line. if(condition) break; The issue in my opinion is readability. I personally dislike breaking a loop other than using the loop condition. Commented Feb 27, 2018 at 15:59
  • 97
    because it consumes 3 lines of code A very, very, very bad reason to dislike any style. IMO "consum[ing] lines of code" is somewhere between irrelevant and a good thing. Trying to stuff too much logic into too few lines results in unreadable code and hard-to-find bugs. Commented Feb 27, 2018 at 16:40
  • 3
    Possibly unpopular opinion: for(int i=0;i<array.length && !condition;i++) is relatively uncommon and may be overlooked by someone just skimming the code; this might be a good use case for a while or do while loop, which more often have multiple break conditions in the loop definition. Commented Feb 28, 2018 at 22:57