Path: utzoo!yunexus!stpl!bbm!darcy From: darcy@bbm.UUCP (D'Arcy Cain) Newsgroups: comp.lang.c Subject: Re: More gotos... Keywords: Well, why not? Message-ID: <790@bbm.UUCP> Date: 12 Sep 89 13:39:54 GMT Article-I.D.: bbm.790 References: <10353@phoenix.Princeton.EDU> Reply-To: darcy@bbm.UUCP (darcy) Organization: BBM Bureau of Measurement, Toronto Lines: 45 In article <10353@phoenix.Princeton.EDU> tbrakitz@phoenix.Princeton.EDU (Byron Rakitzis) writes: >I came across what I thought was a good application for a goto: >token_grabbing_function() > { > > get_a_token: > > while (is_white_space(c = getchar()); /* skip it */ > > /* So, c contains a non-whitespace character */ > > if (c == comment_delimiter) > { > while (c = getchar() != other_comment_delimiter); /* skip it */ > goto get_a_token; > } > else > { > deal_with_the_token_properly_and_return; > } > } > >Can anyone see a goto-less version which is as concise? OK how about; token_grabbing_function() { for (;;) { while (is_white_space(c = getchar()); /* skip it */ /* So, c contains a non-whitespace character */ if (c == comment_delimiter) while (c = getchar() != other_comment_delimiter); /* skip it */ else { deal_with_the_token_properly_and_return; } } } D'Arcy J.M. Cain (darcy@bbm, darcy@cain)