Xref: utzoo misc.misc:6189 comp.misc:6114 Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!sun-barr!cs.utexas.edu!uunet!mcvax!ukc!etive!aiai!ken From: ken@aiai.ed.ac.uk (Ken Johnson) Newsgroups: misc.misc,comp.misc Subject: Re: The "evil" GOTO (Was: 25 Years of BASIC) Message-ID: <415@skye.ed.ac.uk> Date: 5 May 89 10:10:27 GMT References: <1791@ubu.warwick.UUCP> <1436@onion.reading.ac.uk> <1814@ubu.warwick.UUCP> Reply-To: ken@aiai.UUCP (Ken Johnson) Followup-To: comp.misc Organization: AIAI, University of Edinburgh, Scotland Lines: 37 In article <1814@ubu.warwick.UUCP> mirk@uk.ac.warwick.cs (Mike Taylor) writes: >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: "); > } > I like doing it this way: (NB This is not correct C! But I think it is a correct program structure for the problem.) get_sex( ) { return(get_sex_sub("Enter your sex: ")); } get_sex_sub(string) { printf (string); gets(sex) return( (sex == 'm' || sex == 'f') ? sex : get_sex_sub(" or only: ") ); } -- Ken Johnson, AI Applications Institute, 80 South Bridge, Edinburgh EH1 1HN E-mail ken@aiai.ed.ac.uk, phone 031-225 4464 extension 212 Annoy the Labour Party! Pay the Poll Tax!