title: Explanation: How recursion works when a function is called within a loop?
body: <p>[Beginner] </p>
  
  <p>I went through tons of websites, watched tutorials at stretch, everything went in vain.</p>
  
  <p>I stuck with recursion, cannot write/understand beyond writing Factorial of a number using recursion.</p>
  
  <p>I'm trying to understand how combination of a list works</p>
  
  <pre><code>def permute(a, l, r):
      if l==r:
          print a
      else:
          for i in xrange(l,r+1):
              a[l], a[i] = a[i], a[l]
              permute(a, l+1, r)
              a[l], a[i] = a[i], a[l] 
  
  
  string = "ABC"
  n = len(string)
  a = list(string)
  permute(a, 0, n-1)
  </code></pre>
  
  <p>How recursion works in the above script/program?
  Genuinely looking for an answer.</p>
  
  <p>Thank you.</p>