MRAB pyt...@mrabarnett.plus.com 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
2009/10/1 Sion Arrowsmith s...@viridian.paintbox:
MRAB pyt...@mrabarnett.plus.com 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
On Tue, 29 Sep 2009 22:29:10 -0700, John Yeung wrote:
On Sep 29, 1:15 pm, Carl Banks pavlovevide...@gmail.com 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
John Yeung wrote:
On Sep 29, 1:15 pm, Carl Banks pavlovevide...@gmail.com 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
On Sep 29, 6:38 pm, Duncan Booth duncan.bo...@invalid.invalid wrote:
Carl Banks pavlovevide...@gmail.com 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
On Sep 30, 7:12 am, Steven D'Aprano
ste...@remove.this.cybersource.com.au wrote:
On Tue, 29 Sep 2009 22:29:10 -0700, John Yeung wrote:
On Sep 29, 1:15 pm, Carl Banks pavlovevide...@gmail.com wrote:
Hmm, I wonder if Python should emit a warning if an else is used on a
for block with no break
Iain King iaink...@gmail.com 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
On Sep 30, 3:40 am, Iain King iaink...@gmail.com 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
dksr dksre...@gmail.com 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
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
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:
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
On Sep 29, 9:08 am, Gary Herron gher...@islandtraining.com 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
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:
Carl Banks pavlovevide...@gmail.com 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
On Sep 29, 10:38 am, Duncan Booth duncan.bo...@invalid.invalid
wrote:
Carl Banks pavlovevide...@gmail.com 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
On Sep 29, 1:15 pm, Carl Banks pavlovevide...@gmail.com 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
On Sep 29, 1:25 pm, MRAB pyt...@mrabarnett.plus.com 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
20 matches
Mail list logo