Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!necntc!ima!haddock!karl From: karl@haddock.ISC.COM (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: The D Switch Loop?? Message-ID: <2813@haddock.ISC.COM> Date: 2 Mar 88 02:31:43 GMT References: <6548@j.cc.purdue.edu> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Distribution: na Organization: Interactive Systems, Boston Lines: 17 Keywords: switch loop Summary: A proper switch is better In article <6548@j.cc.purdue.edu> ksb@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@haddock.isc.com), The Walking Lint