What is recursion in programming and when to use it?