[Tutor] While and for loops

A.T.Hofkamp a.t.hofkamp at tue.nl
Tue Jul 14 09:12:42 CEST 2009


Todd Matsumoto wrote:
>> while True:
>>     <do something>
>>     for i in items:
>>         if i > 10:
>>             break
>>         else:
>>             <do something>
>>

 > Okay,
 >
 > 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>



More information about the Tutor mailing list