Re: a question about foreach construct

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

Your last two examples, working like a for-loop or a while-loop seem identical.

foreach item in s do 
  -- user code 
end foreach 

would be equivalent to

i = 1 
while i <= length(s) do 
   object item = s[i] 
   -- user code 
   s[i] = item 
end for 

You can add this by creating a preprocessor. The preprocessor will have to use automatic variables other than i, ideally ensuring the i counter does not already exist and is a very long identifier like i21312101240124012414.

Instead of assigning item to s[i], the preprocessor thing could substitute in s[i] for item. It should be done in a way that preserves lines

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

Search



Quick Links

User menu

Not signed in.

Misc Menu