Breaking and returning from a for loop is tempting, but error prone. Using Functional techniques is a much better solution and leads to cleaner more testable code. Use .find to retrieve the first matching element. Closures are not a serious overhead concern that we should avoid them to conserve memory.
I agree with Michael, while loops should be avoided.
I personally cannot remember the last time I used while and for.
But to each their own. You have to maintain and read your code so write it however you want!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Breaking and returning from a for loop is tempting, but error prone. Using Functional techniques is a much better solution and leads to cleaner more testable code. Use .find to retrieve the first matching element. Closures are not a serious overhead concern that we should avoid them to conserve memory.
I agree with Michael, while loops should be avoided.
I personally cannot remember the last time I used while and for.
But to each their own. You have to maintain and read your code so write it however you want!