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
"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
> 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:
>
> 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
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
> &
>> 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:
>
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
>
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 =
> 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
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
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
11 matches
Mail list logo