title: Error Code: UnboundLocalError: local variable referenced before assignment
body: <p>It seems that many get this error but each situation is different.</p>
  <p>My code:</p>
  <pre><code>i = 0
  
  def sort(a):
  
      b = len(a)
  
      if(i == b):
          print (a)
  
      elif(b == 0):
          print ('Error. No value detected...')
  
      elif(b == 1):
          print (a)
  
      elif(a[i]&gt;a[i+1]):
          a[i], a[i+1] = a[i+1], a[i]
  
          i = i + 1
          print(a)
          sort(a)
  </code></pre>
  <p>Error Code:</p>
  <pre><code>Traceback (most recent call last):
   File &quot;&lt;string&gt;&quot;, line 301, in runcode
   File &quot;&lt;interactive input&gt;&quot;, line 1, in &lt;module&gt;
   File &quot;(File location, you don't need to know....)&quot;, line 8, in sort
     if(i == b):
   UnboundLocalError: local variable 'i' referenced before assignment
  </code></pre>
  <p>I am not sure what this error means or what is wrong.</p>