Xref: utzoo comp.lang.c:9814 comp.software-eng:504 Path: utzoo!mnetor!uunet!husc6!cca!g-rh From: g-rh@cca.CCA.COM (Richard Harter) Newsgroups: comp.lang.c,comp.software-eng Subject: State Machines, The Ultimate Goto Message-ID: <27568@cca.CCA.COM> Date: 1 May 88 00:15:05 GMT References: <1988Apr8.183815.3187@utzoo.uucp> <449@goofy.megatest.UUCP> <2200@louie.udel.EDU> <587@vsi.UUCP> <27310@cca.CCA.COM> <760@dlhpedg.co.uk> Reply-To: g-rh@CCA.CCA.COM.UUCP (Richard Harter) Organization: Computer Corp. of America, Cambridge, MA Lines: 36 In article <760@dlhpedg.co.uk> cl@datlog.co.uk (Charles Lambert) writes: >In article <27310@cca.CCA.COM> g-rh@CCA.CCA.COM.UUCP (Richard Harter) writes: >>f) Put the test condition in a while statement and step through the >> actions [somehow]. Unfortunately, I don't see a nice way to do >> this in C. The thought that first occurs to one is something like ... sample code deleted >This is almost a finite-state machine, and state machine programming is an >accepted idiom. Generalise it as follows: ... sample code deleted Strange throat noises resembling the mating call of a frog. [That there is a comment.] State machines are all very well in their way -- I use them myself -- but state machine logic is quintessential goto logic. The essence of state machine logic is that it doesn't matter where you came from; all that matters are the appropriate actions for this state and the appropriate state to transfer to next. From a flow control viewpoint, entering a state machine is like falling into a pin ball machine. You bang around here and there and (if there is a guaranteed halting condition) you eventually get out. Goto logic says leave and don't come back. Heirarchical logic says leave and come back. The prescription against goto's really means -- don't mix the two types of structure. -- In the fields of Hell where the grass grows high Are the graves of dreams allowed to die. Richard Harter, SMDS Inc.