[Python-ideas] Control Flow - Never Executed Loop Body

Pavol Lisy pavol.lisy at gmail.com
Tue Mar 22 13:54:16 EDT 2016


2016-03-21 2:32 GMT+01:00, Steven D'Aprano <steve at pearwood.info>:
[...]
> But, like I said, we're stuck with it, and I'm not seriously proposing a
> change. I think we'd be better off now if the keyword had been "then"
> from the beginning, but the pain of changing it *now* outweighs the
> benefit.

A.
Just a little analyze about this theoretical possibility

for x in seq:
   if good(x):break # (1)
then: all_bad()  # (2)
else: empty() # (3)

(3) seems to be alternative to (2) like "if then else" , but is not ,
it is alternative to (1) "union" (2)

Also empty is not contradictory to all_bad!

'else' seems to be not ideal but yes we have what we have

B.
if we don't want to define new keywords and want to map all (?)
possibilities (empty vs non empty, break vs no break) and don't want
to break backward compatibility then we could analyze this:

for i in seq:
  if cond(i):
    print('non empty & break') # (1)
    break
and: print('non empty & all') # (2)
or: print('no elements') # (3)
else: print('no break') # (4)


(1) is exclusive but (4) could be with (2) or<exclusive> (3)
(2) and (3) are contradictory

I have not opinion about order of and, or, else in this moment.


More information about the Python-ideas mailing list