More gotos...
Byron Rakitzis
tbrakitz at phoenix.Princeton.EDU
Mon Sep 11 17:14:16 AEST 1989
I came across what I thought was a good application for a goto:
say you're scanning an input stream for tokens, and that you
skip over whitespace. Furthermore, suppose that there is a pair
of comment-delimiter characters. You also want to skip over comments.
So:
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?
(I'm ignoring EOF errors and the like for the moment)
Cheers. (ducks for the flames)
--
"C Code."
"C Code run."
"Run, Code, run!"
Byron Rakitzis. (tbrakitz at phoenix.princeton.edu ---- tbrakitz at pucc.bitnet)
More information about the Comp.lang.c
mailing list