Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #108831 > unrolled thread

Re: for / while else doesn't make sense

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2016-05-19 11:02 -0600
Last post2016-05-19 11:02 -0600
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: for / while else doesn't make sense Ian Kelly <ian.g.kelly@gmail.com> - 2016-05-19 11:02 -0600

#108831 — Re: for / while else doesn't make sense

FromIan Kelly <ian.g.kelly@gmail.com>
Date2016-05-19 11:02 -0600
SubjectRe: for / while else doesn't make sense
Message-ID<mailman.37.1463677388.27390.python-list@python.org>
On Thu, May 19, 2016 at 10:31 AM, Herkermer Sherwood <theherk@gmail.com> wrote:
> Most keywords in Python make linguistic sense, but using "else" in for and
> while structures is kludgy and misleading. I am under the assumption that
> this was just utilizing an already existing keyword. Adding another like
> "andthen" would not be good.

"else" makes sense from a certain point of view, but I think that
logic may not be communicated well. At the start of each loop
iteration, the loop construct makes a test for whether the loop should
continue or not. If that test ever fails (i.e. if the condition of the
while loop is false), the else block is executed instead. So you can
think of it as a repeated if-else where the else block has the
additional effect of exiting the loop.

> But there is already a reserved keyword that would work great here.
> "finally". It is already a known keyword used in try blocks, but would work
> perfectly here. Best of all, it would actually make sense.
>
> Unfortunately, it wouldn't follow the semantics of try/except/else/finally.

"finally" in exception handling denotes a block that is *always*
executed. Using it for a block that is only sometimes executed would
dilute that meaning.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web