The correct version is:
def incr_num(x, y): if x <= y: print x incr_num(x+1, y)
Note that x is printed no more than once for each recursive function call.
UPDATE: The reason your function doesn't work is because incr_num(10,10) prints 10 and then calls incr_num(11,10) , which returns immediately. After that, incr_num(10,10) continues. It will not exit the while and continue the next iteration, typing 10 again and calling incr_num(11,10) . As you can see, this cycle does not end.
source share