Replace for Goto
Peter Hansen
peter at engcorp.com
Wed May 28 22:18:09 EDT 2003
Gerhard Häring wrote:
>
> Use a never-ending while loop, then use an "if" and a "break". Like this:
>
> while 1:
> # do stuff
> answer = raw_input("Want to play again? (y/n)").upper()
> if answer == 'N':
> break
>
> > If there is another way, other than a similar thing to Goto, tell me
> > that, as well as a similar thing for goto. It would probably be useful
> > later on...
Hmm... maybe modifying Gerhard's example like this would be more
comfortable to a BASIC person: ( ;-) )
def goto(label): pass
while 1: # assign a label to this line
# do stuff
answer = raw_input('blah blah? (y/n)').upper()
if answer == 'N':
break
goto('while 1') # branch back to labelled line ;-)
(Ooh, I'm mean today. :-)
-Peter
More information about the Python-list
mailing list