Hello!

Fairly recent J enthusiast here. I’m wondering about the idiomatic way to 
iterate at most n times? I.e. do f^:n y, but with the possibility of an early 
exit if some condition is met. Is it (u F. ]) y, where u is f but with some 
Z:’s added? E.g

        f=: 2&*
        MAX=: n

        u=: monad define
_2 Z: -.*MAX=: MAX - 1
_2 Z: some other condition
f y
)

But then you need to globally assign and reassign MAX and this doesn’t feel 
very elegant. Another option of course is to use a for-loop with break.

Thanks, Anton Wallgren
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to