Using recursion instead of for loops.