How can I convert a for loop to a recursive function?
Here is a recursive version of this procedure, in python:

def cat(a,b):
  if a == b:
    return [a]
  else:
    return [a] + cat(a+1,b)


Another option is

def cat(a,b):
  if a == b:
    return [b]
  else:
    return cat(a,b-1) + [b]


These conversions are heavily geared toward this particular function. Here is a more general conversion, in the context of state machines without input (inputs can easily be added):

def run_my_algorithm(state = None):
  if state is None:
    state = initial_state
  if is_final_state(state):
    return extract_answer(state)
  else:
    state = next_state(state)
    return run_my_algorithm(state)


Hopefully the notation is self-explanatory.