I gather you are looking for a more general solution than your specific example. Look at the conjunction "^:" (Power). Raul's solution is perfect for your example as it turns the question around in such a way that you can determine your ending condition without going through all the calculations. "^:" lets you test your previous result to determine if you want to continue. This would still be a loop but certainly not in the traditional form.
On 3/4/07, Geoff Canyon <[EMAIL PROTECTED]> wrote:
I haven't finished reading the docs yet, so forgive me if this is answered someplace: is there a way to terminate the integers function based on a calculation? For example, suppose I want to generate all the primes < 10,000. p:i.500 That generates the first five primes, but has no way of knowing whether that's enough or too much. I'd like to use something like p:i._ which would me give me all the primes (to infinity) but then put a limit on it so that it stops at a certain point -- in this case, when one of the generated primes is about to exceed 10,000. Is there a way to do that without resorting to a traditional loop? regards, geoff ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
