If you switch to Scheme (or the few other tail-recursive languages), you can always use recursion, and it’s the most efficient solution. It’s a bit of a weird shift at first, and the hand-holding do, dotimes, loop macros will let you transition at your own pace, but soon all your “loops” will just be named-let recursion.
If you switch to Scheme (or the few other tail-recursive languages), you can always use recursion, and it’s the most efficient solution. It’s a bit of a weird shift at first, and the hand-holding do, dotimes, loop macros will let you transition at your own pace, but soon all your “loops” will just be named-let recursion.