Re: EOF and GOTO and 0th array element
- Posted by Kat <gertie at PELL.NET> Aug 23, 2002
- 499 views
On 23 Aug 2002, at 10:43, Juergen Luethje wrote: > > Derek <ddparnell at bigpond.com> wrote: > > <snip> > >> 2. At the risk of incurring wrath for writing spaghetti code, is there a > >> GOTO > >> equivalent? > > > Yes and no. Strictly speaking there is no GOTO (thankfully). > > I'm thankful for this, too. > > <snip> > >> 4. Nested in a while...end while loop is a for..end for loop. If a > >> test fails in the for..end for loop I want to exit the while..end while > >> loop. However, using exit command in the for..end for loop seems to > >> only exit the "for" loop and does not apply to the "while" loop. Can > >> one indicate what to exit if using that command, or (as in the example > >> below) do I have to set some condition in the "for" loop to test outside of > >> it in order to exit the "while" loop? > >> > >> . > >> . > >> somemarker=true > >> while 1 do > >> . > >> . > >> -- test values; if fail, exit loop > >> for y=1 to 10 do > >> if test y fails then > >> somemarker=false > >> exit > >> end if > >> end for > >> if somemarker=false then > >> exit > >> end if > >> . > >> . > >> end while > >> . > >> . > >> > > > This request just keeps on coming up. Euphoria doesn't make it easy for us. > > It > > encourages hard-to-read code in this instance. My "pet" solution is a form > > of > > controlled GOTO. > > > > somemarker: while 1 do > > . > > . > > -- test values; if fail, exit loop > > for y=1 to 10 do > > if test y fails then > > exit somemarker > > end if > > end for > > . > > . > > end while > > > For handling such situations more elegant, I'd like to have an enhanced > exit-statement in Euphoria, where the numbers of levels to exit can be > given. Then this code snippet would be as simple as: > > ---------------------------------------- > while 1 do > . > . > -- test values; if fail, exit loop > for y=1 to 10 do > if test y fails then > exit 2 -- exits both the for loop and the while loop > end if > end for > . > . > end while > ---------------------------------------- > > For instance, PowerBASIC has a similar feature (One has to write > "exit,exit" instead of "exit 2".) With this very simple and powerful > feature, the last argument for GOTO will disappear! Nope. As Derik said in his last post, the "end while" is a tag for the "exit" to "goto",, it is a controlled "goto", and an *extremely* controlled one. I would prefer a goto to goto whatever label i specify. What if you code using "exit" or "exit2", and then, in your rapid development system, you you bracket those loops with another? go thu and change all the exitx lines? sheesh. Drop in goto and you need to change nothing. I don't believe the interpreter need to be cobbled by an assortment of exit statements, resumes, leave, break, jump, or loop labels, when one goto and one label for it will take care of this recurring thread. Kat