[fpc-devel] New feature discussion: for-in loop

Marc Weustink marc.weustink at cuperus.nl
Tue Oct 20 10:26:20 CEST 2009


Graeme Geldenhuys wrote:
> 2009/10/20 Alexander Klenin <klenin at gmail.com>:
>> for-in is just a syntax sugar plus standard interface for the cost common usage
>> of iterators. So they are not mutually exclusive at all.
> 
> Another flaw in the for-in concept...
> 
>   What will this do:
> 
>   for y in MyList do
>   begin
>     if y = XXX then
>       MyList.Add(YYY);
>     if y = ZZZ then
>       MyList.Insert(1, AAA);
>   end;
> 
> With my iterator implementation I can handle this with no problems,
> and ever make the resulting behaviour user-selectable with parameters
> to the MyList.GetIterator method.

This is IMO similar to using a for loop vs. using a while loop. In a for 
loop you are not allowed to modify the loop variable. In this case I can 
imagine its not allowed to modify the list. If you want to, use a while 
and iterators.
Yes I know iterators, I use them myself too on my own lists. As said I 
before, I think too that tose can be combined.

Marc








More information about the fpc-devel mailing list