I don’t reason about runtime part for now , but about compile-time part:
It is easy to modify example so it is still needed to iterate array manualy:
i = arr.size-1
while i >= 0
yield(arr[i]) #block can add elements to array
i-=some_fun(arr[i]) # we skip some elements depending on the value of processed element.
end
if I understand correctly it would have to be rewritten to something like
return if arr.size == 0
i = UInt32.new(arr.size)-1
loop do
yield(arr[i])
v = some_fun(arr[i])
break if v > i
i -= v
end