Re: trace(1) bug

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

c.k.lester wrote:
> 
> 
> Anyway, my point is I would never want to use a pre-defined variable
> in a for loop, and neither would anybody else. :D

<snip>
 
> What are the benefits of allowing the use of a pre-declared var in a loop?

I think a lot of the impetus behind this initiative is the C-style for loop,
combined with the C++ ability of declaring variables anywhere in a routine.
A C-style for loop has several parts:

 1:  initialize the starting value (and in C++, possibly declare a new 
     variable with the scope of the loop block.
 2:  an expression to evaluate to determine when to exit the loop (end
     the loop when it evaluates to 0)
 3:  an expression to execute to iterate through the loop

Any of these may be empty statements, BTW.  A typical loop might look
something like this:

for( int i = 0; i < max; i++ ){
    // do stuff
}
...which is equivalent to:
for i = 0 to max-1 do
    -- do stuff
end for

But you can also do something like (to mix euphoria and C):
for(object i = gets(fn); sequence(i); i = gets(fn))

end for

It's really more of a structured while loop, where the iterators and 
conditions are all neatly contained at the top of the loop, though the
loop variable (if it exists) can be modified anywhere in the loop, since
it's a regular variable.

I've often considered trying this out in ooeu, since it's such a useful
construct.

Matt

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

Search



Quick Links

User menu

Not signed in.

Misc Menu