Re: [Tutor] While and for loops

2009-07-14 Thread A.T.Hofkamp
Todd Matsumoto wrote: Okay, I'm not sure if this is good practice, but I could assign a variable within the while loop, that is assigned something that will then break the outer loop. while True: breakout = True for i in items: if i > 10: breakout = False

Re: [Tutor] While and for loops

2009-07-14 Thread Alan Gauld
"wesley chun" wrote as i mentioned in my other msg, you need another break statement that is *not* in another loop. in your case, not in the for-loop. you need a break statement somewhere within your while block (again, that's not in any other loop). IOW, it should be indented at the same level

Re: [Tutor] While and for loops

2009-07-14 Thread wesley chun
> I'm not sure if this is good practice, but I could assign a variable within > the while loop, that is assigned something that will then break the outer > loop. > > while True: >    breakout = True >     >    for i in items: >        if i > 10: >            breakout = False >        else: >    

Re: [Tutor] While and for loops

2009-07-14 Thread wesley chun
> So how would you break out from this situation? as i mentioned in my other msg, you need another break statement that is *not* in another loop. in your case, not in the for-loop. you need a break statement somewhere within your while block (again, that's not in any other loop). IOW, it should be

Re: [Tutor] While and for loops

2009-07-14 Thread Todd Matsumoto
Okay, Thanks guys. That explains it. Cheers, T Original-Nachricht > Datum: Tue, 14 Jul 2009 00:16:30 -0700 > Von: wesley chun > An: "A.T.Hofkamp" > CC: Todd Matsumoto , "tutor@python.org" > Betreff: Re: [Tutor] While and for loops > &

Re: [Tutor] While and for loops

2009-07-14 Thread wesley chun
>> So how would you break out from this situation? > > finished = False > while not finished: >     >     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: >      

Re: [Tutor] While and for loops

2009-07-14 Thread Todd Matsumoto
else: if break is False: break Is the above do-able? Is there a better way? T Original-Nachricht > Datum: Tue, 14 Jul 2009 00:05:30 -0700 > Von: wesley chun > An: Todd Matsumoto > CC: tutor@python.org > Betreff: Re: [Tutor] While and for loops >

Re: [Tutor] While and for loops

2009-07-14 Thread A.T.Hofkamp
Todd Matsumoto wrote: while True: for i in items: if i > 10: break else: > Okay, > > So how would you break out from this situation? > finished = False while not finished: for i in items: if i > 10: finished =

Re: [Tutor] While and for loops

2009-07-14 Thread wesley chun
> Can you run for loops in while loops and if yes, why did my if condition not > break the loop? > > I read that loops sort of have an order of precedence, does that have > anything to do with this problem? todd, welcome to Python! you're right in that your questions are related to each other

Re: [Tutor] While and for loops

2009-07-14 Thread Todd Matsumoto
Okay, So how would you break out from this situation? T Original-Nachricht > Datum: Tue, 14 Jul 2009 06:57:41 + > Von: sli1...@yahoo.com > An: "Todd Matsumoto" > Betreff: Re: [Tutor] While and for loops > Your break is for the for loop not the

[Tutor] While and for loops

2009-07-13 Thread Todd Matsumoto
Hello, The other day I was playing with a while loop with a for loop nested inside. Within the for loop I had a condition to break the loop, but when loop ran it never existed the loop. I went back and looked in Programming Python to read about loops and I've got two questions (related to each