Re: New keyword added: continue
- Posted by CChris <christian.cuvier at agri?ulture.gouv.?r> May 12, 2008
- 807 views
Kat wrote: > > > Why? > Here's how you use one keyword instead of six: > > }}} <eucode> > > --repeat until > :repeat > x -= 1 > if x > 12 then goto repeat end if > > > -- case > atom fred, a, d > fred = 45 > a = 1 > d = 44 > > goto x > puts(1,x&" is not covered") goto caseend > :1 puts(1,"it's 1!") goto caseend > :34 puts(1,"wow, 34!") > :"Sam" puts(1,"you got Sam!" goto caseend > :a+d puts(1,"Yep, fred is 45!") goto caseend > :caseend > > -- continue, retry, restart, and next > :restart > for loop = 1 to 12 do > :retry > -- code > if test = failed then goto retry end if > if thistest = failed then goto restart end if > if bored = true then goto next end if > if done then goto demoend end if > -- code > :next > end for > :demoend > > </eucode> {{{ > > You know exactly where each "goto" lands, each :target can be in your own > native > language, and OOEU prooves it can be done. It's ONE word. It's so SIMPLE. > > Kat You know where each goto lands, granted. But you don't know where you land from, as any label can be targeted from scarrered places. And that's why soem people are downright against it, and why I don't like using it. I had found out this: when you start writing code, and it is naive an simple, then goto are as easy to read as anything, and perhaps easier. Then, the code becomes more complex because there's a handful of special cases, and you now have to guarantee that it hardly matters, when you reach a label, what was the program state just before. It simply doesn't work. You can always set up flags, but then tell me that you never make mistakes updating them... I tried to implement goto in Æ. It works. But I added a twist: all goto statements must have a label, and there is another builtin, come_from(), which retrieves the last goto label you jumped from. Otherwise, I'd say: goto is nice, it's one keyword instead of 6, is not hard to type, but it makes maintaining code so much trickier. Pascal compilers didn't recognise goto, unless a specific option was turned on. Perhaps that would be the way to go: if you want goto, have it, but know that you are doing things the hard way. I still think some equivalent of come_from() is necessary to make goto usable in the Euphoria framework - you know, that world where raw pointers are considered unsafe -. CChris