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*

8
  • 1
    Nice. There are times when you need to do A and B in order with a test T exactly between them. The usual A T(B A) priming pattern does this but duplicates A. Any general alternatives to this general pattern? Commented Apr 19, 2016 at 18:25
  • 2
    See the last bit of code in my answer. Commented Apr 19, 2016 at 18:25
  • That one's a classic. Would you ever suggest using a break? Commented Apr 19, 2016 at 18:27
  • I'm not opposed to early exits from a loop if doing so simplifies the code. Sometimes you can just return. Commented Apr 19, 2016 at 18:28
  • 1
    An example would be looking for the first occurrence of a string in each line of a text file. You would still need the while loop, but once you found the string in the line you just read, you could either break or return. Commented Apr 19, 2016 at 18:37