Re: goto's, and loops
- Posted by Kat <KSMiTH at PELL.NET> Jul 29, 1999
- 552 views
----- Original Message ----- From: Irv Mullins <irv at ELLIJAY.COM> To: <EUPHORIA at LISTSERV.MUOHIO.EDU> Sent: Thursday, July 29, 1999 12:58 PM Subject: Re: goto's, and loops > On Thu, 29 Jul 1999, you wrote: > > 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. ) > > Let's see what you've written: > > > loop1-------------- > > something | > > loop2 -------------|--------- > > test var, maybe goto | | > > -- an "exit" | | > > EndOfLoop1---------- | > > more code | > > EndOfLoop2------------------ > > :target > > Follow the lines. That's why > 1. you don't see gotos' in all languages, and > 2. you get a D on the assignment, > unless you can find a real life example where this construct works under all > test conditions, and cannot be replaced with simpler, properly nested code.. /me looks all over for the aforementioned code that Irv wrote.. Ooops, i just threw that together, with the EndOfLoop1 and EndOfLoop2 swapped. But assuming i hadn't swapped them ( ie they were correctly placed ), i don't see anything easier than David Cuny's code (thanks, David) which used 2x as much screen space,, so a "goto" would have been easier and prolly faster to execute. Granted that goto's *can* lead to spagetti code, but they don't *force* you to write spagetti code. The lack of a goto can lead to setting and testing and clearing exit variables. If we must use exit variables in nested loops, this seems to say that there is no point in using "while" (which test their var at the top of the loop) or "for" loops when nesting, just use infinite loops ("if true then") and "exit"s,, `cause you use the exit var anyways, hmm, i could get addicted to exit vars.. where "exit" substitutes for a "goto -- remark at end of this loop". Ok, what about "repeat-until" loops? I didn't see them in Euphoria either. It's a "while-do" loop with the test at the end instead of the beginning. Yes, there are ways around most, if not all, things missing in a language, but a simple *local* goto, which wouldn't leave the procedure or function it is in, would be nice. In my humble opinion. If there was a vote i missed or anything... etc.. Kat