Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!njin!princeton!phoenix!tbrakitz From: tbrakitz@phoenix.Princeton.EDU (Byron Rakitzis) Newsgroups: comp.lang.c Subject: More gotos... Keywords: Well, why not? Message-ID: <10353@phoenix.Princeton.EDU> Date: 11 Sep 89 07:14:16 GMT Organization: Princeton University, NJ Lines: 36 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@phoenix.princeton.edu ---- tbrakitz@pucc.bitnet)