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*

4
  • 2
    Recommending array.find begs the question, as we then have to discuss the best way to implement array.find. Unless you're using hardware with a built-in find operation, we have to write a loop there. Commented Aug 11, 2018 at 0:44
  • 2
    @Barmar I disagree. As I indicated in my answer, a lot of heavily-used languages provide functions like find in their standard libraries. Undoubtedly, these libraries implement find and its kin using for loops, but that's what a good function does: it abstracts the technical details away from the function's consumer, allowing that programmer to not need to think about those details. So even though find is likely implemented with a for loop, it still helps make code more readable, and since it's frequently in the standard library, using it adds no meaningful overhead or risk. Commented Aug 11, 2018 at 0:54
  • 4
    But a software engineer has to implement these libraries. Don't the same software engineering principles apply to library authors as application programmers? The question is about writing loops in general, not the best way to search for an array element in a particular language Commented Aug 11, 2018 at 1:02
  • 4
    To put it another way, searching for an array element is just a simple example that he used to demonstrate the different looping techniques. Commented Aug 11, 2018 at 1:06