title: Are there any memory/other overheads between returning after a `break` in a while loop and a `return` whilst inside a while loop?
body: <p>Are there any memory/other overheads between returning after a <code>break</code> in a while loop and a <code>return</code> whilst inside a while loop?</p>
  
  <p>For example, in <code>test1</code> I can see that when the function returns, the variable <code>attempt</code> is deleted.</p>
  
  <pre><code>def test1(n):
      attempt = 0
      while True:
          value = random.random()
          if value &lt; n:
              break
  
      return value
  </code></pre>
  
  <p>What about in <code>test2</code>? Is the variable <code>attempt</code> still deleted from memory when the function returns or is it kept in memory?</p>
  
  <pre><code>def test2(n):
      attempt = 0
      while True:
          value = random.random()
          if value &lt; n:
              return value
  </code></pre>
  
  <p>What are the differences between writing code one way or another?</p>