Lord Yggdrasill wrote:in which circumstances would you rather use recursion instead of loops?
When the recursive version is more elegant, easier to understand, and the recursive depth or stack memory use will not cause a problem.
Lord Yggdrasill wrote:And is there a reason for preferring one over the other? Considering a situation in which you are mapping database information into model fields/properties, is it better to use recursion or loops?
Generally, iteration should be preferred to avoid running into the problem of exceeding the maximum recursion depth. Related to this, iteration will likely be more efficient in memory usage, even if there must be the use of an explicit stack (since you can choose to save in the stack the necessary data and nothing else).