Re: For loops

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

c.k.lester wrote:
> 
> Matt Lewis wrote:
> > 
> > I think that there's a legitimate place for something like the C-style 
> > for-loop.  It gives us a fairly well structured while loop that I think
> > makes for clearer code, since the mechanics of the loop are declared 
> > before hand, but you have much greater freedom in choosing your method
> > of iteration and termination.
> 
> Would this be too far outside Euphoric philosophy:
> 
> }}}
<eucode>
> for( x, x+1, x < 10)
> -- ...
> end for
> </eucode>
{{{


Yes. way too far!  I would prefer that what we have now continues to work.
I feel, having thought a bit, that CChris's idea to allow the scope of the
for loop iterator to persist beyond the loop as a constant is pretty good.
It allows the programmer access to the value of the iterator when the loop
decided to terminate (not always when the limit is reached) without doing
any harm to existing code.

I also feel the continue statement would be valuable but I have never liked 
the choice of word. Would "next" be better? Implying that the next loop is to
commence immediately?

for i=1 to 10 do
      if array[i] < 0 then
         next   -- Do no more processing this time around
      end if
      <do something>
      if some_condition then
         exit   -- Quit processing maybe before limit reached
      end if
   end for

   ?i           -- Can tell at what point the loop exited


I agree of course that it is possible to do any of these things with the
existing language structure, but making things clearer and simpler is great
for code maintenance.

AndyD

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

Search



Quick Links

User menu

Not signed in.

Misc Menu