Re: foreach

new topic     » goto parent     » topic index » view thread      » older message » newer message
mattlewis said...
DerekParnell said...

Ok. However keep in mind that I'll be proposing a 4.x modification to the for family of statements that would allow declaring the loop variable outside the actual for statement so it can have a wider scope.

Something like ...

integer c 
for defined c = 1 to 10 do 
    if func(c) then exit end if 
end for 
printf(1, "The value of 'c' is %d\n", c) 

That makes sense to me. In fact, I'd say that rather than use the define keyword, simply require the type declaration if you want a new variable. Any 'naked' foreach variable would then have to be already declared. So really, it's probably no more difficult to follow this path for 4.0 than not.

The main issue to consider (which I think you had brought up, and then so did Jeremy):

jeremy said...

In 4.1 we can safely add features such as updating x and have it reflected in the original list, adding a reversed parameter, etc... As said previously, the above would cover 90% of all uses of foreach.

While I certainly see the utility in this, the more I think about it, it's not a very euphorian concept. Everywhere else in the language, we have assignment by value, and then here we have something operating by reference. So not something to be done lightly, I think...

Matt

I'm good with that as long as the following still crashes with an error.

integer varCT, varEbull 
for varCT = 1 to 10 do 
  for varEbull = 1 to 10 do 
    for varCT = 1 to 10 do -- Attempt to reuse active for loop variable 'varCT' 
    end for 
  end for 
end for 
--Just thought I would use something stranger than foo and bar. grin 
--Sound them out. 

Lucius L. Hilley - Unkmar

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

Search



Quick Links

User menu

Not signed in.

Misc Menu