Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Else statement executing when it shouldnt

Thread Tools

Else statement executing when it shouldnt

Frank Millman
Posts: n/a
On 23/01/2013 15:35, Jussi Piitulainen wrote:
> Thomas Boell writes:
>> Using a keyword that has a well-understood meaning in just about
>> every other programming language on the planet *and even in
>> English*, redefining it to mean something completely different, and
>> then making the syntax look like the original, well-understood
>> meaning -- that's setting a trap out for users.
>> The feature isn't bad, it's just very, very badly named.

> I believe it would read better - much better - if it was "for/then"
> and "while/then" instead of "for/else" and "while/else".
> I believe someone didn't want to introduce a new keyword for this,
> hence "else".

There is a scenario, which I use from time to time, where 'else' makes
perfect sense.

You want to loop through an iterable, looking for 'something'. If you
find it, you want to do something and break. If you do not find it, you
want to do something else.

for item in iterable:
if item == 'something':
else: # item was not found

Not arguing for or against, just saying it is difficult to find one word
which covers all requirements.

Frank Millman

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Null Argument shouldnt be? A. Anderson C++ 8 06-28-2007 09:03 PM
Why shouldnt I get Vista (or which version) Nik Coughlin NZ Computing 27 02-09-2007 12:37 AM
Which of switch statement and if-else statement takes less time to execute? C Programming 21 08-02-2005 09:24 AM
shouldnt this evaluate in a scalar context??? dutone Perl Misc 8 07-02-2004 04:46 PM
reroute to another url, but the first url must shouldnt change in theadress-mask guenther schoebel HTML 2 10-10-2003 07:44 AM