Rewards Network Interview Question

How to do safe recursion in Scala?