[Tutor] can I make a while loop true again

Dave Angel davea at davea.name
Tue Feb 11 13:03:35 CET 2014


 Ian D <duxbuz at hotmail.com> Wrote in message:
> Thanks for the help on the last one.
> 
> Is it possible to restart a while loop? This doesn't work at all (surprise surprise)
> 
> import turtle as t
> 
> def start():
>     global more
>     more = True
>     
> def stop():
>     global more
>     more = False
> 
> more = True
> 
> while True:
>     while more:
> 
>         t.onkey(stop, "space")
>         t.onkey(start, "Up")
>         t.fd(1)
>         t.listen() 		 	   		  
>

Sure. Follow the 'while more' loop with a 'while not more' one,
 still inside the 'while True' one.

While True:
      while more:
            ....
       while not more:
            ....

But you really should move those calls to onkey outside the loop. 
 They are just confusing things there. How many times do you have
 to set the same event handler?

-- 
DaveA



More information about the Tutor mailing list