From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,4e34524ff567b8b1 X-Google-Attributes: gid103376,public From: "Matthew Heaney" Subject: Re: GOTO in ADA Date: 1999/08/14 Message-ID: <37b62ac7@news1.us.ibm.net>#1/1 X-Deja-AN: 512912681 Content-transfer-encoding: 7bit References: <6A08418D0DAA75E0.E4D1854DB5A80C85.B4B03E27B8C9304C@lp.airnews. net> X-Trace: 15 Aug 1999 02:49:43 GMT, 129.37.213.195 Organization: Global Network Services - Remote Access Mail & News Services X-Notice: should be reported to postmaster@ibm.net Content-Type: text/plain; charset="US-ASCII" Mime-version: 1.0 Newsgroups: comp.lang.ada X-Complaints-To: postmaster@ibm.net Date: 1999-08-14T00:00:00+00:00 List-Id: In article <6A08418D0DAA75E0.E4D1854DB5A80C85.B4B03E27B8C9304C@lp.airnews.net> , Ray wrote: > I know that the use of GOTO statements are anathema to most diehard > structured programmers, but can someone give an example of a valid use > of the GOTO in "real life" code? Typically, you use a goto statement when implementing a state-driven abstraction. I do this all the time when using tasks. For example: task body T is begin select accept Initialize do end; or accept Finalize; goto Terminate_Task; end select; <
> null; ... accept Finalize; goto Terminate_Task; ... goto Main; <> null; end T; Another classic example is an FSM, say a parser or scanner. You use a goto statement to easily navigate among the states. This question comes up a lot on comp.lang.ada. Search DejaNews for other threads. In general, you should feel free to use a goto. As Robert Dewar pointed out: (start of message) From: dewar@merv.cs.nyu.edu (Robert Dewar) Subject: Re: State Machine Implementation Date: 06 Aug 1998 00:00:00 GMT Message-ID: References: <35C90369.CFE8ED98@inficad.com> X-Complaints-To: usenet@news.nyu.edu X-Trace: news.nyu.edu 902413682 27275 (None) 128.122.140.58 Organization: New York University Newsgroups: comp.lang.ada <> A case statement is possible certainly, and it is hard to know exactly what you mean by "an implementation", since this is the sort of thing that occurs all the time in a programs, and the application dependent details are 95% of the code anyway. Note that an alternative, probably more efficient, and for many people more readdable way of coding a finite state machine in languages like Ada is to use a label on each state, and goto's to effect state transition, thus efficiently encoding the state in the program counter. Some people have this silly allergy to goto's (a case of understanding an important principle without really understanding it), but in fact this is for many programmers one of the very few legitimate uses of gotos. (end of message) -- It is impossible to feel great confidence in a negative theory which has always rested its main support on the weak points of its opponent. Joseph Needham, "A Mechanistic Criticism of Vitalism"