Re: New keyword added: continue
- Posted by CChris <christian.cuvier at agric?ltur?.gouv.fr> May 28, 2008
- 783 views
Kat wrote: > > Derek Parnell wrote: > > > > Kat wrote: > > > }}} <eucode> > > > :restart > > > for loop = 1 to 12 do > > > :retry > > > -- code > > > if blah then goto restart end if > > > if blorg then goto retry end if > > > if not x then goto exit end if > > > if CK then goto next end if > > > if worstcase then goto cleanup&return end if > > > -- code > > > :next > > > end for > > > :exit > > > </eucode> {{{ > > > > Hi Kat, > > just a few of quick questions ... > > > > ** How, as a maintainer of the code above, can I be sure that process flow > > only > > gets to the "restart:" label from either the statement immediately preceding > > it or the 'goto' inside the loop? In other words, how can I be sure that > > there > > is not another 'goto restart' elsewhere in the code? > > You can't. You read the code to see if there is another "goto" that label. The > same with "exit", "return", etc.. I have a fair amount of code that has > "return" > sprinkled around, and no one has ever complained about more than one place > leaving > the function. One way to restrict the "where from" is to localise all "goto" > to procedure/function blocks, and not allow it in top level code. Exactly like > in OOEU. > > > ** If I have to place another looping construct within the same scope as the > > one above, what should I call the labels? > > Umm, how about "loop2" ? Or you mean the targets for more "goto" of the same > umm, form? Pick a name. You have the freedom to restart the inner loop, the > outer loop, the nested while loop in there which you added later, etc.. I tend > to give my nested loop names some description, even if it's just "index1", so > i could have a "goto restart_index1", which sorta reads easily, and i know > just > where it's going, and i can get there with the one "goto" keyword from any > depth > of nested loops. The target being present alerts me, as i am reading down the > code, that i may be going back to that point from somewhere. > > > ** Under what circumstanes might I have to rename the labels? > > Never, i believe. If you add loops, or other code, you do not need to change > anything, assuming your intent to goto the :target is the same. If you wish > to add a target, choose another name. Like i said, i tend to use the loop name > as part of the target, and/or/as well as the purpose, if i need any > clairification, > rather insuring unique target names. This way i can wrap or unwrap nested > loops, > and not have a problem, as well as skip blocks during debug. > > With goto scope restricted to proc/funct blocks, it makes some code even > easier, > such as "goto cleanup&return", which i know has the local scope of variables, > is at the bottom of the block where code will fall thru to anyhow, and execute > the "cleanup&return". With Eu the way it is now, i have hunks of code > copy/pasted > thruout which does the cleanup with local vars and returns, and those hunks > are a nightmare to keep identical. Just as an aside, one other cure for that > would be nested procedures, which could be called inside the nesting > procedure, > and the nested one have the scope of the nesting one's vars, i did this in > Turbo > Pascal a *lot*. > > I believe Matt scored 100 with the way he did goto in OOEU, and i reiterate > my suggestion all of OOEU be merged into Eu v4. > > Kat Which I'd support, with probably reservations about namespace handling. CChris