Re: goto's, and loops
- Posted by Roderick Jackson <rjackson at CSIWEB.COM> Jul 29, 1999
- 553 views
Hi Kat, If I read Rob (and the language) correctly, one of the guiding principles of Euphoria is that a programmer shouldn't do something that others (or he himself, later on) will find extremely difficult to understand, debug or change. This is part of "the Euphorian philosopy" of coding, language design, and programming in general. Now, I've seen examples where gotos have been used in code without being at all troublesome, fitting cleanly in the algorithm. But, the potential for abuse with the goto statement is absolutely monstrous. Sure, it CAN be used well; but remember the Euphorian philosophy. When I was introduced to the concept of structured programming (while using BASIC), I started trying to NOT use gotos, and it helped my coding. It was easier for me to remember what my code did, and it helped organize my code into logical subsections. Rob's decision to leave out the goto does have a number of advantages, and fits with the Euphorian philosophy. Since using QBasic and becoming more experienced with program flow, I haven't missed it. It might take some getting used to, but you'll find that anything that can be done with a goto can be done without; of course, in some cases the goto is just plain easier to use. As to your example... the short answer would be "redesign the algorithm," but that's not always desireable. One specific approach would be to leave the code pretty much the way it is, but use local variables to store certain states. The result would look something like: ConditionFlag = 0 -- this is FALSE for i = w to x do -- some code for j = y to z do if (s[i][j] = 0) then ConditionFlag = 1 -- this is TRUE exit end if end for if (not (ConditionFlag)) then -- more code end if end for Hope this helps you out some... Rod ---------- From: Kat[SMTP:KSMiTH at PELL.NET] Sent: Thursday, July 29, 1999 10:49 AM To: EUPHORIA at LISTSERV.MUOHIO.EDU Subject: goto's, and loops Hi all, Why is there no "goto" in Euphoria? It would be easy enough to implement, and if you don't want to use it, you don't haveto. I've used it sparingly in other languages, for the example below, for example. Maybe i am in a rut, but i don't see an nice way to do this example in Euphoria, can you help, please? ( Without making another procedure and all the vars global. ) loop1 some code loop2 test var, maybe goto target -- an "exit" here would get you out of loop2, not loop1 EndOfLoop1 more code EndOfLoop2 :target thanks, Kat