Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!seismo!mimsy!chris
From: chris@mimsy.UUCP (Chris Torek)
Newsgroups: comp.lang.c
Subject: Re: goto's
Message-ID: <7687@mimsy.UUCP>
Date: Sat, 25-Jul-87 00:18:44 EDT
Article-I.D.: mimsy.7687
Posted: Sat Jul 25 00:18:44 1987
Date-Received: Sat, 25-Jul-87 17:15:04 EDT
References: <3289@bigburd.PRC.Unisys.COM> <7571@beta.UUCP> <765@haddock.ISC.COM> <960@fmsrl7.UUCP>
Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742
Lines: 51

In article <960@fmsrl7.UUCP> grazier@fmsrl7.UUCP (Kevin Grazier) writes:
>On a more intangible level, I seem to remember being taught as an undergrad
>that there are still a COUPLE (and I mean just that) algorithms that
>can't be done without a goto.

To prove otherwise to yourself, consider any program that contains
at least one `goto' statement.  The section of code to which this
branches is either normally reachable, or reachable only by a goto.

(The following may be flawed; I have not bothered to check it
carefully.  Nonetheless the general idea ought to be right.)

Case I: Normally reachable.

Replace the beginning of the program with
    
	while not prog_done do

and the end of the program with

	if not doing_goto or did_goto then prog_done <- true; fi;
	end while;

Now protect every single statement except those which would be
executed by the `goto' with

	if not doing_goto then ; fi;

At the beginning of the section performed by the goto, add

	if doing_goto then did_goto <- true; fi;

Change the goto statement to

	doing_goto <- true;

Add two global variables:

	boolean doing_goto <- false, did_goto <- false;

Case II: Not normally reachable.

Move the unreachable code anywhere within the scope of the main
program and protect it with `if not doing_goto then ; fi;'.
The problem has now been reduced to case I.

This can be repeated for all remaining goto statements, using
different variable names for the pair of booleans.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
Domain:	chris@mimsy.umd.edu	Path:	seismo!mi (Ssed to