[Python-Dev] Re: switch statement

Greg Ewing greg.ewing at canterbury.ac.nz
Tue Apr 26 07:00:21 CEST 2005

Donovan Baarda wrote:

> Agreed. I don't find any switch syntaxes better than if/elif/else. Speed
> benefits belong in implementation optimisations, not new bad syntax.

Two things are mildly annoying about if-elif chains as a
substitute for a switch statement:

1) Repeating the name of the thing being switched on all the time,
    and the operator being used for comparison.

2) The first case is syntactically different from subsequent ones,
    even though semantically all the cases are equivalent.

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg.ewing at canterbury.ac.nz	   +--------------------------------------+

More information about the Python-Dev mailing list