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.

3
  • I like this, as a thoughtful and balanced overview, even if it in a sense refuses to answer the question posed. I find that the for( range ){ if( condition ){ action } }-style makes it easy to read things one chunk at a time and only uses knowledge of the basic language constructs. Commented Jul 19, 2016 at 19:43
  • @PJTraill, the way the question was phrased reminded me of Raymond Chen's rant against the for-if antipattern, which has been cargo-culted and somehow became an absolute. I totally agree that for(...) if(...) { ... } is often the best choice (that's why I qualified the recommendation to split the action into a subroutine). Commented Jul 20, 2016 at 0:16
  • 2
    Thanks for the link, which clarified things for me: the name “for-if” is misleading, and should be something like “for-all-if-one” or “lookup-avoidance”. It reminds me of the way Abstraction inversion was described by Wikipedia in 2005 as when one “creates simple constructs on top of complex (ones)” — until I rewrote it! Actually I wouldn’t even rush to fix the lookup-process-exit form of for(…)if(…)… if it was the only place lookup occurred. Commented Jul 20, 2016 at 9:49