Re:How not to teach recursion (2021)
by pwdisswordfish9 on Saturday June 18, 2022 @12:51PM
(#31791567)
Iteration is just recursion over a list/array/generator.
[ Parent
| on HN ]
I don't know if that's a helpful framing?
def sum(arr):
total = 0
for x in arr:
total += x
return total
and def sum(arr):
if len(arr) == 0:
return 0
return arr[0] + sum(arr[1:])
both operate over an array but I'd call one of them recursive and the other iterative.