in reply to Re: checking an array of numbers for a particular value
in thread checking an array of numbers for a particular value
The standard grep caveat applies - you could end up doing more work here than you actually wanted.
From the OP: I want to check an array of numbers for a particular value, and if found do something.
Personally, I read this as, "I'm looking for one value to operate upon." But, in general, if you're only looking for a single occurrence of a value, it's better to use a foreach loop (or another explicit loop - while/for/whatever).
The reason is that the grep doesn't stop. So, for example, if the element you're looking for is the first item in your list, the grep solution will still process the entire list looking for additional instances. If you're using one of the looping constructs, you can perform your operation and last out of it when you find the value you're looking for.
|
|---|