title: quit and exit do not work inside while loop
body: <p>Using <code>Spyder</code> on <code>windows10</code>.</p>
  <p>This keeps running infinitely when one might expect the code to <code>exit</code> if <code>i&gt;3</code>:</p>
  <pre><code>import time
  
  i = 0
  while True:
      i+= 1
      print('hello')
      time.sleep(1)
  
      if i &gt; 3:
          exit()
          quit()
  
  </code></pre>
  <p>So neither the <code>quit()</code> nor <code>exit()</code> functions work.</p>
  <p>However, this does <code>exit</code> when <code>i&gt;3</code>:</p>
  <pre><code>import sys
  import time
  
  i = 0
  while True:
      i+= 1
      print('hello')
      time.sleep(1)
  
      if i &gt; 3:
          exit()
          quit()
          sys.exit()
  
  </code></pre>
  <p>It is noted that the <code>break</code> function works, but the requirement is for the code to terminate (as opposed to breaking out of the loop and continuing).</p>
  <p>It is also noted from this question (<a href="https://stackoverflow.com/questions/51797957/code-still-executes-after-quit-or-exit-python-spyder">Code still executes after &quot;quit&quot; or &quot;exit&quot;, Python, Spyder</a>) that this is a <code>spyder</code> issue.</p>
  <p>Why is this the case and, given the above, what is the best way to exit a while loop preferably without requiring an <code>import</code> ?</p>