2009/10/1 Sion Arrowsmith :
> MRAB wrote:
>>> [ for ... else ]
>>The example that makes it clearest for me is searching through a list
>>for a certain item and breaking out of the 'for' loop if I find it. If I
>>get to the end of the list and still haven't broken out then I haven't
>>found the it
MRAB wrote:
>> [ for ... else ]
>The example that makes it clearest for me is searching through a list
>for a certain item and breaking out of the 'for' loop if I find it. If I
>get to the end of the list and still haven't broken out then I haven't
>found the item, and that's when the else statem
dksr wrote:
> Yes thats what I thought. for-else looks similar to if-else and in if-
> else, else part is executed only when if part is not executed, but in
> for-else it has entirely a different job.
If you think of if-else more in terms of the else-branch occurring
when the if-condition is no l
On Sep 30, 3:40 am, Iain King wrote:
> Read the suggestion again - it's not a warning on the for-else
> structure, it's a warning when the for-else doesn't contain a break;
> he's theorising that a for-else without a break will always trigger
> the else, in which case it's almost certainly an erro
Iain King wrote:
> However, I assume you can get past the else by raising an exception,
> so the idea becomes a little muddled - do you warn when there is no
> break and no explicit raise caught outside the loop? What about an
> implicit exception? I would guess that code intentionally using an
On Sep 30, 7:12 am, Steven D'Aprano
wrote:
> On Tue, 29 Sep 2009 22:29:10 -0700, John Yeung wrote:
> > On Sep 29, 1:15 pm, Carl Banks wrote:
> >> Hmm, I wonder if Python should emit a warning if an else is used on a
> >> for block with no break inside. I don't think the else can be invoked
> >>
On Sep 29, 6:38 pm, Duncan Booth wrote:
> Carl Banks wrote:
> > Hmm, I wonder if Python should emit a warning if an else is used on a
> > for block with no break inside. I don't think the else can be invoked
> > in any other way. As a bonus it could catch some cases where people
> > mistakenly
John Yeung wrote:
On Sep 29, 1:15 pm, Carl Banks wrote:
Hmm, I wonder if Python should emit a warning if an else is
used on a for block with no break inside. I don't think the
else can be invoked in any other way. As a bonus it could
catch some cases where people mistakenly use it thinking it
On Tue, 29 Sep 2009 22:29:10 -0700, John Yeung wrote:
> On Sep 29, 1:15 pm, Carl Banks wrote:
>> Hmm, I wonder if Python should emit a warning if an else is used on a
>> for block with no break inside. I don't think the else can be invoked
>> in any other way. As a bonus it could catch some cas
On Sep 29, 1:25 pm, MRAB wrote:
> The example that makes it clearest for me is searching
> through a list for a certain item and breaking out of
> the 'for' loop if I find it. If I get to the end of the
> list and still haven't broken out then I haven't found
> the item, and that's when the else
On Sep 29, 1:15 pm, Carl Banks wrote:
> Hmm, I wonder if Python should emit a warning if an else is
> used on a for block with no break inside. I don't think the
> else can be invoked in any other way. As a bonus it could
> catch some cases where people mistakenly use it thinking it
> will execu
On Sep 29, 10:38 am, Duncan Booth
wrote:
> Carl Banks wrote:
> > Hmm, I wonder if Python should emit a warning if an else is used on a
> > for block with no break inside. I don't think the else can be invoked
> > in any other way. As a bonus it could catch some cases where people
> > mistakenly
Carl Banks wrote:
> Hmm, I wonder if Python should emit a warning if an else is used on a
> for block with no break inside. I don't think the else can be invoked
> in any other way. As a bonus it could catch some cases where people
> mistakenly use it thinking it will execute when there are no
Ethan Furman wrote:
Sandy wrote:
Hi all,
A simple and silly if-else question.
I saw some code that has the following structure. My question is why
else is used there though removing else
has the same result. More important, is it not syntactically wrong :-(
for i in xrange(8):
if i < 4:
On Sep 29, 9:08 am, Gary Herron wrote:
> Sandy wrote:
> > Hi all,
> > A simple and silly if-else question.
> > I saw some code that has the following structure. My question is why
> > else is used there though removing else
> > has the same result. More important, is it not syntactically wrong :-(
If I'm reading the indentation correctly, the else is applying to the for
loop, not the if statement.
When used in this way, the else occurs only if the for loop exits due to
completion (aka, the for loop does not exit due to a break or return
statement).
I would expect the output from that code
Sandy wrote:
Hi all,
A simple and silly if-else question.
I saw some code that has the following structure. My question is why
else is used there though removing else
has the same result. More important, is it not syntactically wrong :-(
for i in xrange(8):
if i < 4:
print i
else:
Sandy wrote:
Hi all,
A simple and silly if-else question.
I saw some code that has the following structure. My question is why
else is used there though removing else
has the same result. More important, is it not syntactically wrong :-(
for i in xrange(8):
if i < 4:
print i
else:
Sandy wrote:
Hi all,
A simple and silly if-else question.
I saw some code that has the following structure. My question is why
else is used there though removing else
has the same result. More important, is it not syntactically wrong :-(
for i in xrange(8):
if i < 4:
print i
else:
Hi all,
A simple and silly if-else question.
I saw some code that has the following structure. My question is why
else is used there though removing else
has the same result. More important, is it not syntactically wrong :-(
for i in xrange(8):
if i < 4:
print i
else:
print i
Chee
20 matches
Mail list logo