while True:
input = raw_input(\"enter input: \")
result = useInput(input)
def useInput(input):
if input == \"exit\":
break #return 0 / quit /
You can raise an exception and handle it outside of while
... but that will likely result in some confusing code ...
def useInput(in_):
if in_ == "exit":
raise RuntimeError
try:
while True:
input = raw_input("enter input: ")
result = useInput(input)
except RuntimeError:
pass
It's MUCH better to just return a boolean flag and then break or not depending on the value of that flag. If you're worried that you already have something you want to return, don't fret -- python will happily let your function return more than one thing:
def func()
...
return something,flag
while True:
something,flag = func()
if flag:
break