The D Switch Loop??
Karl Heuer
karl at haddock.ISC.COM
Wed Mar 2 12:31:43 AEST 1988
In article <6548 at j.cc.purdue.edu> ksb at s.cc.purdue.edu.UUCP (Kevin Braunsdorf) writes:
>For a replacement for C why can't we make a switch statement loop? We
>can make switch less of a hack in the lanuage.
That's a step backwards. `if` and `switch` are for selection, `for` and `do`
and `while` are for loops; I see no need for a construct that does both.
Given the existence of a proper `switch` statement (one in which the cases do
not fall through into each other), your example can be written more cleanly:
insert a `for (;;)` in front of the `switch`, and remove the `continue`
statements. The `break`, no longer meaningful to `switch`, now exits the
`for` loop.
(Personally, I'd probably write it as a `while` and a `switch`, so I wouldn't
need the `break` either. This would require a temporary for the `switch`
parameter, but one usually needs that anyway when handling `default`.)
Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint
More information about the Comp.lang.c
mailing list