More gotos...
D'Arcy Cain
darcy at bbm.UUCP
Tue Sep 12 23:39:54 AEST 1989
In article <10353 at phoenix.Princeton.EDU> tbrakitz at 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 at bbm, darcy at cain)
More information about the Comp.lang.c
mailing list