The final word on GOTO (Don't I wis
Peter da Silva
peter at ficc.uu.net
Fri Oct 6 02:58:02 AEST 1989
Code deleted, see parent article.
In article <725 at thor.wright.EDU>, bkottman at thor.wright.edu (Brett Kottmann) writes:
> This must be really old code since in C, execution falls through
> to the next case anywasy; in every case without the goto, it would hit
> donum: anyways...(albiet after trying the rest of the case statements)
Yes, but if you looked at what the code *does*, you would see that you
don't want to execute those statements.
> A break usually replaces the goto in that type of code.
In this case it wouldn't. Here's a goto-less version of the multiple
lead-in case that should have you all puking:
switch(format_char) {
case 'd': the stuff I put under d; if(0) {
case 'o': the stuff I put under o; if(0) {
case 'x': the stuff I put under x; if(0) {
case 'u': the stuff I put under u; }}}
the stuff I put under donum;
}
I know it's not the best way to remove the gotos, but it's legal C
without a single "unstructured" element.
It's always possible to "remove" the gotos. It's not always worth it.
Structured programming is a discipline, not a game.
--
Peter da Silva, *NIX support guy @ Ferranti International Controls Corporation.
Biz: peter at ficc.uu.net, +1 713 274 5180. Fun: peter at sugar.hackercorp.com. `-_-'
``I feel that any [environment] with users in it is "adverse".'' 'U`
-- Eric Peterson <lcc.eric at seas.ucla.edu>
More information about the Comp.lang.c
mailing list