Break outside loop Python function other options -


i have code:

def playagain1():     print("would keep boxing or quit while ahead? (y/n)")     playagain = input().lower()     if(playagain.startswith('y') == false):         print("whatever chicken.")         break 

i want break loop if playagain() doesn't start y. whenever try, error:

'break' outside loop

how write better make work?

as matt bryant's answer states, can't break outside loop can return function. add need return value function, main programme loop knows whether return start or quit:

def main():     while true:         # main game code goes here         if not playagain():             break  def playagain():     print("would keep boxing or quit while ahead? (y/n)")     response = input().lower()     return response.startswith('y') 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -