Re: New keyword added: continue
- Posted by Jeremy Cowgar <jeremy at ?owgar.c?m> May 12, 2008
- 757 views
Kat wrote: > > Depends on how it's done. In some languages, the loop is nearly a second > program, > and leaving it's code space clears everything that's not in the proc/funct > it's > nested in. Such "nearly a 2nd program" also justified nesting functions and > procedures inside other functions of procedures, making the internal proc/func > local to the proc/func it was nested in. I don't know how Eu does it. Yes, that's how it would be done, but in your example, there were things like endcase, endfor, etc... those are outside the loop. > > #2 with the for loop, it suffers the same fate as the case statement. Sure, > > on the first for loop you can use :retry, :end, :next, :restart, but then on > > subsequent for loops in the same context (in top level or inside a > > function), > > you would have to get creative in your naming... :end2, :next2, :restart2, > > etc... > > Then have 1 for loop that is nested in another, and then later in the > > function > > you add a new for loop. Then, as time goes on, you add a for loop at the > > beginning > > of the function. Now, your first for loop is named :end3, :restart3, and > > your > > second is just :end, :restart, etc... and an inner is :restart3, etc... It > > begins > > to get pretty confusing. > > OMGess, do you really program like that? > Do I have nested loops? I sure do. Do I sometimes go back and add a new loop to a function? I sure do. That's all the above was showing, but using your example of goto. Because it is such a mess, I was using it as a case against using a goto as you described. > > So, while I personally think a goto statement is a good thing, I do not > > think > > it is a replacement for exit, continue and a case statement. > > I nominate it again for exit, continue, restart, next, retry (not the error > handling retry), or any other keyword where the purpose is to get around > intervening > code. In your example of nested loops, i have no clue where an exit would > goto, > and in most cases i bet it would not goto where i wanted. There's been > numerous > posts showing an exit not traveling far enough, leading to more flag tests to > see if it's necessary to exit some more. One goto would have been enough, and > quite clear, mentioning a descriptive target at both ends of the jump, and > easy > to find with text search in an editor. An exit and continue could be modified pretty easy to do something like this:
for a = 1 to 5 do for b = 1 to 5 do for c = 1 to 5 do exit 2 -- exit 2 loops end for -- never reached puts(1, "Hello!\n") end for printf(1, "%d,", {a}) end for
Output of above is 1,2,3,4,5. The same could be done for continue. Before enabling goto to exit a loop, I would nominate the above construct. If a parameter was not given to exit or continue, it would simply exit 1 loop as normal. However, can we please move goto discussions to the new Goto? thread? Thanks. -- Jeremy Cowgar http://jeremy.cowgar.com