[Tutor] While and for loops

Todd Matsumoto tmatsumoto at gmx.net
Tue Jul 14 09:17:26 CEST 2009


Okay,

Thanks guys.

That explains it.

Cheers,

T
-------- Original-Nachricht --------
> Datum: Tue, 14 Jul 2009 00:16:30 -0700
> Von: wesley chun <wescpy at gmail.com>
> An: "A.T.Hofkamp" <a.t.hofkamp at tue.nl>
> CC: Todd Matsumoto <tmatsumoto at gmx.net>, "tutor at python.org" <tutor at python.org>
> Betreff: Re: [Tutor] While and for loops

> >> So how would you break out from this situation?
> >
> > finished = False
> > while not finished:
> >     <do something>
> >     for i in items:
> >         if i > 10:
> >             finished = True  # Do not do the next while-iteration
> >             break            # and break out of the for loop
> >         else:
> >             <do something>
> 
> 
> this solution is workable as well, plus it avoids having 2 break
> statements in the code. it "breaks" out of the while-loop in a natural
> way, making its conditional False.
> 
> -- wesley
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> "Python Web Development with Django", Addison Wesley, (c) 2009
> http://withdjango.com
> 
> wesley.j.chun :: wescpy-at-gmail.com
> python training and technical consulting
> cyberweb.consulting : silicon valley, ca
> http://cyberwebconsulting.com

-- 
Neu: GMX Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate
für nur 19,99 Euro/mtl.!* http://portal.gmx.net/de/go/dsl02


More information about the Tutor mailing list