No, they're different concepts.
- When iterating over a problem, you're solving it step by step (iterative) and in one layer.
- When using recursion, you're solving a problem layer by layer by recursive calls ("code calling itself again").
It's possible (and very likely) to combine both concepts in real code.
For example, to walk through some tree structure (JSON or XML), you'd typically end up with some function like this (pseudo code):
function parseNode(node) {
// process this node
switch (node.type) {
// ...
}
foreach (child in node.children) // iterate over all child nodes
parseNode(child) // this is the recursive call
}
Let's assume you've got the following tree with nodes:
A
|
B-+-C
| |
E F-+-G
To start parsing the tree, you'd call parseNode(A)
.
This would trigger the processing in the following order: A, B, E, C, F, G
As you can see, this will walk the tree branch by branch. When going down by one step/depth, you've got a recursive call. Whenever you switch to the next sibling, you're iterating.