Python Break Inside Function
<p>I am using Python 3.5, and I would like to use the <code>break</code> command inside a function, but I do not know how.
I would like to use something like this:</p>

<pre><code>def stopIfZero(a):
    if int(a) == 0:
        break
    else:
        print('Continue')

while True:
    stopIfZero(input('Number: '))
</code></pre>

<p>I know that I could just use this code:</p>

<pre><code>while True:
    a = int(input('Number: '))
    if a == 0:
        break
    else:
        print('Continue')
</code></pre>

<p>And if you don't care about the <code>print('Continue')</code> part, you can even do this one-liner:
<code>while a != 0: a = int(input('Number: '))</code>(as long as a was already assigned to something other than 0)
However, I would like to use a function, because other times it could help a lot.</p>

<p>Thanks for any help.</p>

<p>You want to use <code>return</code>, not <code>break</code>. </p>

<p><a href="https://docs.python.org/3/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops" rel="nofollow"><code>break</code></a> is used to stop a loop. </p>

<blockquote>
  <p>The break statement, like in C, breaks out of the smallest enclosing for or while loop.</p>
</blockquote>

<p><a href="https://docs.python.org/3/reference/simple_stmts.html#return" rel="nofollow"><code>return</code></a> is used to exit the function and return a value. You can also return <code>None</code>. </p>

python function python-3.x break