Re: Open Source

new topic     » goto parent     » topic index » view thread      » older message » newer message

Jason Gade wrote:
> 
> I also like the idea of "continue <label>" or "next <label>" where label
> is an optional identifier at the beginning of a loop. But I haven't given it
> too
> much thought.
> 

I would like to suggest three additions to the syntax of Euphoria which would
get around 99% of the desire for a goto. Nothing new but as suggested above:

   next var    -- Go to the iteration point of the for loop for this variable
   exit var    -- Ditto but exit the loop
   redo var    -- Ditto but re-run the loop without iterating the variable

For nested loops the interpreter would have to release variables which were
out of scope, but that is simple enough. If you have three nested loops
using I, J & K, say, and in the middle had "next I", then that would be coded
as exit K; exit J; next I;

for i=1 to 10 do
      for j=1 to 10 do
         for k=1 to 10 do
            if some condition met then
               next i
-- effectively: exit k
--              exit j
--              next i
            end if
         end for
      end for
   end for


These three would make the nested loop control much easier to code and much
easier to read. And the desire for goto would almost vanish. Most people who
ask for goto statements want them for exiting nested loops, it seems to me.

Any suggestions? Anyone able to add these to the interpreter?

Andy Drummond

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu