I've recently had to write a function that needed to use recursion. Now I got tripped up writing the function. So for my own records and in case someone else makes the same mistake I'm documenting my own school boy error.

Don't forget to return the recursion. My mistake was to not add in a return statement. So I had something like:

def recurse(x)
  while x < 10:
    print x
    x += 1
    recurse(x)

Silly mistake

That doesn't work, you need to return the call to recurse:

def recurse(x)
  while x < 10:
    print x
    x += 1
    return recurse(x)

The correct way

Needless to say its a silly mistake but one I fell into, whoops, fool!