On 03/11/2017 11:49, Jon Ribbens wrote:
On 2017-11-03, Steve D'Aprano <steve+pyt...@pearwood.info> wrote:

Right, which is what happens with the for...else block.

No. Ok, so look. It's obvious that you and I have different mental
models of the situation here. You're thinking of 'for...else' as two
arbitrary clauses that run consecutively unless the whole thing is
aborted by a 'break', whereas I'm thinking of the 'for' clause as
being a search for a situation that matches a condition and the
'else' clause being what happens if the condition is not matched
(i.e. exactly the same as 'if...else').

Now there's nothing inherently *wrong* with your choice of mental
model, except it's leading you into confusion because my model means
the meaning of the 'else' keyword is intuitive and obvious, and yours
means it's counter-intuitive and confusing. Your suggestion is that
the fix is to change the language, my suggestion is to fix your model.
I'd suggest that changing your mind is easier than changing the
language ;-)

I don't think there will be a short keyword that will suit everyone. It may be necessary to use this to spell out exactly how it works:

  for i in r:
     pass ...
  after_normal_loop_termination_then:
     pass ...

(And now, there is the possibility of having an additional 'else' clause to cover abnormal termination via break. This time what 'else' does is more obvious.)

--
bartc
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to