Is there no switch function in Python
Jaime Wyant
programmer.py at gmail.com
Fri Sep 10 11:24:56 EDT 2004
Don't blame c++. This is a relic of 'C'.
http://catb.org/~esr/jargon/html/D/Duffs-device.html
On Fri, 10 Sep 2004 11:16:12 -0400, Roy Smith <roy at panix.com> wrote:
> Isaac To <iketo2 at netscape.net> wrote:
> > C switch is much more flexible than one would expect. It is not just
> > a cheap replacement of a sequence of if-then-else. E.g., in an
> > exercise of "The C++ Programming Language" of Bjarne Stroustrup, you
> > can see the following example code:
> >
> > void send(int *to, int *from, int count) {
> > int n = (count + 7) / 8;
> > switch (count % 8) {
> > case 0: do { *to++ = *from++;
> > case 7: *to++ = *from++;
> > case 6: *to++ = *from++;
> > case 5: *to++ = *from++;
> > case 4: *to++ = *from++;
> > case 3: *to++ = *from++;
> > case 2: *to++ = *from++;
> > case 1: *to++ = *from++;
> > } while (--n > 0);
> > }
> > }
>
> La-de-dah, Bjarne discovers loop unrolling. You don't need a switch
> statement to unroll loops.
>
> Hold on a second. Cases 1 through 7 jump into the middle of the do
> loop!? Pardon me while I barf. I didn't even know that was legal.
> That's the kind of code that gives C++ a bad name.
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list