# is there a mode to use Select instead this while loop?

I've a list where a I want to pick up my first element which matches my criteria. This is my work around:

While[n < Length[listRedPoint],
If[Sign[listRedPoint[[n]].Take[w, 2] + w[[3]]] != -1,
wrongData = {listRedPoint[[n]], -1};
Break[]
];
n++
];


where listRedPoint is a list of m pairs {x_n,y_n}, w is a 3-dimension vector wrongData is the data picked up. In general is there any way to optimize this search-algorithm without use while loop? (Select[]?)

• It seems Select can do what you want, have you tried to use it? – Kuba Jun 13 '16 at 8:58
• I've tried Select[listRedPoint,Sign[#.Take[w, 2] + w[[3]]] != -1,1] but i got an error.... – user3371854 Jun 13 '16 at 9:22
• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Michael E2 Jun 13 '16 at 10:33

SelectFirst instead of While-Break.
SelectFirst[listRedPoint,

• i suggest also SelectFirst[listRedPoint, Sign[#.Take[w, 2] + Last[w]] > 0 &,1] for users with version <10.... – user3371854 Jun 14 '16 at 19:16