title: How recursive functions work inside a 'for loop'
body: <p>I'm fairly new in 'recursive functions'. So, I'm trying to wrap my head around why we use recursive functions and how recursive functions work and I think I've a fairly good understanding about it.</p>
  
  <p>Two days ago, I was trying to solve the shortest path problem. I've a following graph(it's in python): </p>
  
  <pre><code> graph = {'a': ['b', 'c'],
               'b': ['c', 'd'],
               'c': ['d'],
               'd': ['c'],
               'e': ['f'],
               'f': ['c']}
  </code></pre>
  
  <p>I'm just trying to find a path, not the shortest path.So, here is the code:</p>
  
  <pre><code>def find_path(graph,start,end,path=[]):
      path = path + [start]
      #Just a Test
      print(path)
  
      if start == end:
          return path
  
      if start not in graph:
          return None
  
      for node in graph[start]:
          if node not in path:
              new_path = find_path(graph,node,end,path)
          if new_path:
              #Just a test
              print(path)
              return new_path
  
  print(find_path({'a':['b','c'],'b':['c','d'],'c':['d'],'d':['c'],'e':
  ['f'],'f':['c']},'a','d'))
  </code></pre>
  
  <p>My starting vertex is 'a' and the ending vertex is 'd'.</p>
  
  <p>In the fourth line I just printed the 'path' to see where the path goes.</p>
  
  <p>On line 17th I also printed the 'path', again just to test. And here is the result: </p>
  
  <pre><code>['a']
  ['a', 'b']
  ['a', 'b', 'c']
  ['a', 'b', 'c', 'd']
  ['a', 'b', 'c']
  ['a', 'b']
  ['a']
  ['a', 'b', 'c', 'd']
  </code></pre>
  
  <p>The first four lines of the result is the result of 'print(path)' on line 4 of the code. But, line 5th, 6th and 7th is the result of 'print(path)' on line 17th of the code.</p>
  
  <p>My question is why the list of the path is decreasing by one vertex each time?</p>
  
  <p>I've been trying to find it's solution for 2 days. I've went to forums, read the documentation about recursion and watched videos. But, no luck.</p>
  
  <p>I would be greatful if somebody can answer.</p>