Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!mailrus!uunet!hsi!stpstn!lerman From: lerman@stpstn.UUCP (Ken Lerman) Newsgroups: comp.lang.c Subject: Re: Usage of goto's Message-ID: <5624@stpstn.UUCP> Date: 29 Sep 90 13:01:41 GMT References: <1990Sep28.121230.17767@NCoast.ORG> Reply-To: lerman@stpstn.UUCP (Ken Lerman) Organization: The Stepstone Corporation, Sandy Hook, CT 06482 Lines: 52 In article <1990Sep28.121230.17767@NCoast.ORG> ramsey@NCoast.ORG (Cedric Ramsey) writes: -> ->Hello once again peoplekind. I have a question about goto's. We all ->know that there usage is taboo in any language but what better way ->do we have to implement finite state machines. A switch statement ? ->All a switch statement is a goto statement, internally that is. So ->then, maybe it is okay to implement goto's for NFA's, DFA's, and ->transition diagrams. -> ->Is it okay for a programmer to break a TABOO intentionally; by design? IMHO, yes. In one situation where I cared about efficiency, I felt justified in using a bunch of gotos in the same program. The code looked something like this. /* state1 is the state where some pixels may be clipped. state2 is the state where all pixels are clipped. state3 is the state where no pixels are clipped. */ state1name: { /*...*/ if(someCondition)goto state1name; else if(someOtherCondition)goto state2name; else goto state3name; } state2name: { /*...*/ if(someCondition)goto state3name; else goto state1name; } state3name: { /*...*/ if(someCondition)goto state2name; else goto state1name; } Each state was carefully commented as to its functionality. Each was a block of code which was entered at the top. At the time, I felt that the code could be written most cleanly using gotos. (That may not be true of the code above.) Of course, the other place one should feel free to use gotos is as the output of an automatic tool (such as YACC). Ken