Recursive:
relating to or involving the repeated application of a rule, definition, or procedure to successive results. |
Meaning that the next result requires that the rule be applied to previous results. For example, the Fibonacci sequence (
Fn = Fn-1 + Fn-2
).
Iterative:
relating to or involving iteration, especially of a mathematical or computational process. |
Iteration
the repetition of a process or utterance |
Meaning to apply the same process over and over again.
They aren't mutually exclusive words, but they are a little more specific in computer science. A recursive function is a function that calls itself. An iterative function simply isn't recursive. I could be wrong about this, but the only time I've heard someone being specific about an "iterative" solution is one where they are specifically saying "do not use the recursive one".
Furthermore, it would not be wrong to say something along the lines of "the fourth iteration of the recursive function". We would be talking about the fourth time that the function had called itself.
Just to repost PCrumley48's example, here is a recursive factorial:
1 2 3 4 5 6
|
int factorial( int value )
{
if ( value == 0 ) return 1;
return value * factorial( value - 1);
}
|
And here is the iterative solution:
1 2 3 4 5 6 7 8
|
int factorial( int value )
{
int result = 1;
for ( int i = 2; i <= value; ++i )
result *= i;
return result;
}
|
Edit: Iteration is mostly described to apply something on every value of a container:
1 2 3 4 5 6
|
// declare an array
int array[] = { 1, 2, 3, 4, 5 };
// iterate through the array, multiplying each value by 2
for ( int i = 0; i < 5; ++i ) // forgive the magic number
array[i] *= 2;
|