Not sure I understand fully what your question is. I'll try to answer the best I can.
In its basic form, recursion looks like this:
RECURSIVE_FUNCTION (n):
IF <base case>:
RETURN c [where c is some discreet value]
ELSE:
RETURN RECURSIVE_FUNCTION(n') [where n' is some value computed from n, but differing from n]
END IF.
END FUNCTION.
Each recursive function has a
base case which causes it to terminate. This is where recursion ends. The function no longer calls itself, and that 'chain' of recursive calls comes to a close.
In the example above, concerning the return values, in the base case I have it returning 'c', which simply means a value in its own terms, not in terms of the recursive function. Since this is the base case, we cannot call itself again. However, in the recursive case (else), we must perform some modification on the input value to pass along to the next recursive call. The reason we must do this is because if we called the recursive function again using the same input, we would have an infinite loop. Whatever modification you perform to the input value brings it closer and closer to the base case, eventually causing the function to terminate.
In your example above, the halting condition (base case) is handled by this line:
for(i=2; i<=j; i++){
Eventually, the square root of the input will get so small (because you divide it in half with each recursive call) that it will be less than 2, causing the recursion to halt. However, that's not the only thing that will cause this function to halt. Suppose the input is 5. The for loop will run once, but fail the mod check, and so it won't recursively call itself on the first pass. Then, i increments, which causes the for loop to exit and terminate the function.
This also conveniently highlights where your code is broken for us as well: In the example above, the prime factorization of 5 should be: "5". However, your logic causes the function to terminate without printing anything.
Use 16 as your input and walk through the steps with pencil and paper to see how it works: You'll find the result of your above algorithm will be: "2, 2, 2", which is
not the prime factorization of 16, but rather of 8.
In other words, you're missing the output of the final number in the series after recursion ceases. Hope that helps.