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*

7
  • 2
    The code examples cited here mix several different issues. Early & multiple returns (which for me go to the size of the method (not shown)), array search (which begs for a discussion involving lambdas), foreach vs. direct indexing... This question would be more clear and easier to answer if it focused on just one of these issues at a time. Commented Aug 10, 2018 at 15:38
  • 5
    Possible duplicate of Should methods always return from one place? Commented Aug 10, 2018 at 15:45
  • 1
    I know those are examples, but there are languages that have APIs to handle exactly that use case. I.e. collection.contains(foo) Commented Aug 10, 2018 at 20:17
  • 2
    You may want to find the book and reread it now to see what it actually said. Commented Aug 11, 2018 at 6:32
  • 1
    "Better" is a highly subjective word. That said, one can tell at a glance what the first version is doing. That the second version does exactly the same thing takes some scrutiny. Commented Aug 11, 2018 at 22:40