do_times(n, fn, @key from = 0, init)
Return the final value of the function fn
, after calling it n
times.
The starting value of n
is specified by the from
keyword argument.
Fn
take three arguments - the current value of n
, the value returned by
the previous call to fn
and a function that can be called to exit from the
loop prematurely. The initial value of the second argument is specified by
the init
keyword argument.
do_times(5, ^(n, p, _) n + p, init = 0)
// 10
do_times(5, ^(n, p, return) if (n == 4) return(p) else n + p, init = 0);
// 6