Re: EOF and GOTO and 0th array element
- Posted by Juergen Luethje <jluethje at gmx.de> Aug 23, 2002
- 496 views
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! <quote> Many authors have suggested language features [...] which are expressed in terms of *exit*, *jump-out*, *break*, or *leave* statements. Kosaraju [57] has proved that such statements are sufficient to express all programs without *go to*'s and without any extra computation, but only if an exit from arbitrarily many levels of control is permitted. <unquote> [Knuth, Donald E.: Structured Programming with go to Statements. Computing Surveys, Vol. 6, No. 4, December 1974, pp. 261-301] > ---------------- > cheers, > Derek Parnell Regards, Juergen