A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2001-November/018631.html below:

[Python-Dev] switch-based programming in Python

[Python-Dev] switch-based programming in PythonPaul Svensson paul@svensson.org
Thu, 15 Nov 2001 06:55:39 -0500 (EST)
On Thu, 15 Nov 2001, Greg Ewing wrote:

>Donald Beaudry <donb@abinitio.com>:
>
>> In a for or while, the else clause only gets executed when
>> the statement terminates "normally" (not due to a break).  Following
>> this model, one might expect the else clause associated with a 'when'
>> statement to be executed whenever a when's in caluse terminates
>> normally.  But what does "normally" mean in this context?
>
>No, please, don't try to make it work like the loops do!  By the
>principle of least astonishment when coming from other languages, that
>would be a nightmare.

Yes, it should work exactly like the loops do;
it's just Donald who's confusing how `else' clauses on loops work,
There's nothing "normal" about running to the end of a loop.

The `else' clause is entered when the (explicit or implicit) test
of the main statement fails.
This is how it works with `if', `except', and loops.
Anything else would be confusing and error-prone.

Thus, in the below code, one and only one of the three functions is called.

    select flip_eggs:
        when 1:
            sunny_side_up()
        when 2:
            over_easy()
    else:
        scrambled()


		/Paul




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4