Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!hplabs!otter!kers From: kers@otter.hpl.hp.com (Chris Dollin) Newsgroups: comp.misc Subject: Re: The "evil" GOTO (Was: 25 Years of BASIC) Message-ID: <1860005@otter.hpl.hp.com> Date: 5 May 89 07:58:23 GMT References: <1814@ubu.warwick.UUCP> Organization: Hewlett-Packard Laboratories, Bristol, UK. Lines: 62 Mike Taylor said: (In an probably fruitless attempt to stem a public GOTO war, I am prepared to have a private email war with Mike and report back later - see end of article.) | In article <3, I think> gould@rosemary.cs.reading.ac.uk (Adrian Gould) writes: | > Lets eradicate the GOTO from all languages. | | I hate it when people say things like that; As if you can just wave a | magic wand over a language by excising GOTO, and everything will be | alright. Listen, just 'cause Quiche-eater Wirth connected GOTOs with | lack of structure geenrally, doesn't mean either that (A) ALL use of | GOTO is unstructured and obfuscatory, or that (B) ALL obfuscated code | is due to use of GOTO -- so why is it that so many people seem to | believe these myths? | | How many times have you seen this kind of code? | | printf ("Enter your sex: "); | while (sex != "m" && sex != "f") { | gets (sex); | if (sex != "m" && sex != "f") | printf (" or only: "); | } | Not very often. | Why make the test twice? Huh? Huh? Answer me that, all you obsessed | anti-GOTO campaigners. The *natural* way to express the above is: | | printf ("Enter your sex: "); | LABEL: gets (sex); | if (sex != "m" && sex != "f") { | printf (" or only: "); | GOTO LABEL; | } I don't know about "natural". Is programming "natural"? But, using the word within the meaning of the Act, I'd say the natural way to write this is: printf( "Enter your sex: "); repeat gets( sex ); until sex == "m" or sex == "f"; printf( " or only: " ) endrepeat; Of course, if you want to write it like this in C, you'd have to do something like: PROMPT; /* Stuff it, I'm not writing it */ while( GETS, CONDITION ) REPROMPT; /* out all over again. */ Structured programming is not about omitting GOTOs, but using control structures suitable for the task at hand. The idiom you mention is usually called the "N-and-a-half-times loop", and should damn well be supported in *any* imperative programming language. Tell you what, Mike; mail me and we'll talk about this without cluttering the net. Then we can summarise our battle - ahem, enlightened debate - later.