2 conjunctions with monad only versions shown for simplicity

repeatuntil =: 2 : 'for_i. y do. if. v"_ s =. u i do. s break. end. end.'

repeatwhile =: 2 : 0
out =. i.0
for_i. y do. if. v"_ s =. u i do. out break. else. out =. out , s  end. end.
)

   +:  repeatuntil (6 < ]) 2 1 3 2 4 5 2
8
   +:  repeatwhile (6 < ]) 2 1 3 2 4 5 2
4 2 6 4

both short circuit based on finding an exit condition.  I'd be surprised that a 
tacit version is possible, but maybe through scan '/' and ^: ?

I understand that the example is silly overkill, but the main application is 
for repeatuntil is searching in many locations sorted by the likelihood of 
finding it in a location.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to