#include <iostream>
usingnamespace std;
void recursive(int n, int lim) {
if ( n < lim ) {
cout << n << endl;
recursive(n+1,lim);
}
}
void iterative(int n) {
for ( int i = 0 ; i < n ; i++ ) {
cout << i << endl;
}
}
int main()
{
iterative(5);
recursive(0,5);
}
Recursion is simpler if you can count down to 0, as you don't have to keep passing the end condition around.
Or more generally, recursion is simpler if the problem naturally divides into similar (but smaller) problems. Like n! is expressed in terms of (n-1)! until you reach the trivial 1! and/or 0!.