I want to iterate over a list, and return the index as long as I found the first element satisfying my condition. Written in a for loop:
f[x_]:=2x For[i=1, i<=10, i++, If[f[i]==10, Return[i]] ]
And I know a way to write this in Mathematica:
Position[f/@Range, 10, 1, 1]
However, in this code, a list of
f, f, ..., f is all calculated before the
Position executes. In my real problem, f is a costly function. I don't want to, and it is unnecessary to calculate the rest when the first is found. How can I do this using functional style of Mathematica (no loops, ++s)?