Marc Weustink <marc.weust...@cuperus.nl>:

> Graeme Geldenhuys wrote:
>
> > 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;
> > 
[...]
> 
> 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.

But how's the compiler supposed to know which method modifies MyList and which 
one does not? Disallowing all calls to the methods of MyList doesn't seem a 
proper solution, if you're not allowed to do that what is the sense of 
iterating through it? Another option: Raise an exception if the code detects 
that the list changed during the loop? Can it be guaranteed that a changed list 
is detected (usually the answer is: No). At what run-time costs can it be 
detected at all? Etc. pp.

There seems more to that than just syntactic sugar.


Vinzent.
-- 
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to