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

Paul Ishenin webpirat at mail.ru
Tue Oct 20 14:31:26 CEST 2009


Marc Weustink wrote:
> I can see a use for using iterators in a for loop, however they should 
> be declared with some keyword.
>
> Something like
>
> type
>   TListIterator = iterator(TList, init_func, next_func, check_func)
>     function init_func: Boolean;
>     function next_func: <element type>
>     function check_func: Boolean;
>   end;
>
> begin
>   for element in list using TListIterator do...
>
> IMO this is more pascal than using some interface or predefined 
> function names.
Good idea. What is iterator internally? Is this an object with the 
special header?

Is it internall the same as:
TListIterator = object
  function init_func(AList: TList): Boolean;
  function next_func: Pointer;
  function check_func: Boolean;
end;

Best regards,
Paul Ishenin.



More information about the fpc-devel mailing list