Re: a question about foreach construct

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

Adding a new keyword syntax like this is kind of hard. There was a pretty decent discussion about this back in 2008.

I think there are a few small hurdles to get over, namely in the way of expected syntax and behavior. We have to answer questions like:

Can we modify the inner variable from within the block?

foreach item in s do 
    if item = something then 
        item += value -- is this legal? 
    end if 
end foreach 

Can we modify the outer sequence from within the block?

foreach item in s do 
    if item = something then 
        s = append( s, new_item ) -- is this legal? 
    end if 
end foreach 

Should foreach act like a for loop?

for i = 1 to length( s ) do 
    object item = s[i] 
 
end for 

Should foreach act like a while loop?

integer i = 1 
while i <= length( s ) do 
    object item = s[i] 
 
    i += 1 
end while 

-Greg

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

Search



Quick Links

User menu

Not signed in.

Misc Menu