[Tutor] While and for loops
wesley chun
wescpy at gmail.com
Tue Jul 14 09:16:30 CEST 2009
>> 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
More information about the Tutor
mailing list