for / while else doesn't make sense

Rustom Mody rustompmody at gmail.com
Tue Jun 14 11:33:53 EDT 2016


On Tuesday, June 14, 2016 at 8:13:53 AM UTC+5:30, Steven D'Aprano wrote:
> No. The sun exploding was me gently mocking you for your comment disputing
> the "unconditional" part. Yes, you are technically right that technically
> the "else" block will only run if no "break" is reached, and no "return" is
> reached, no exception is raised, also that os._exit or os.abort aren't
> called, the CPU doesn't catch fire, and the world isn't destroyed.
> 
> If we try to enumerate all the things which could prevent the "else" block
> from running, we'll be here for decades. But, and this is the point that
> everyone seems to have missed, * every single one of those things* is
> completely independent of the for...else statement.
> 
> *Including* the presence or absence of a "break".

This is real wild:  A break that is inside a for is independent of the for?!?!

Thats about as meaningful a statement as saying that the algebraic expression
"x² + 1" has a value independent of "x"

However see below

> 
> If you want to understand how Python statements work, you should understand
> them in isolation (as much as possible), which then allows you to
> extrapolate their behaviour in combination with other statements. Most
> lines of Python code are understandable in isolation, or at least close to
> isolation. You can get *very close* to a full understanding of Python by
> just reading one line at a time (with perhaps a bit of short term memory to
> remember if you are compiling a function, building a class, etc).
> 
> E.g. you don't need to understand for loops to understand if...else.
> 
> And vice versa: for...else has a well-defined meaning and operates in a
> simple fashion in isolation of other language features. Its not compulsory
> to put a "return" statement inside your for loop. Nor is it compulsory to
> put a "raise" inside it. And "break" is not compulsory either.

This *desire* for what you call isolation is a standard tenet of
semantics and is right

It is called compositionality

Inn programming: https://en.wikipedia.org/wiki/Denotational_semantics#Compositionality

More general linguistics: https://en.wikipedia.org/wiki/Principle_of_compositionality

However gotos break compositionality unless one introduces heavy artillery like
continuations

And break is a euphemism for goto



More information about the Python-list mailing list