yzfwsf wrote:I don’t know if my understanding is correct? C++ only needs to modify the pointer for each iteration, while FB needs to copy the Node instance every time.
FOR/NEXT in fbc is not as generic as C/C++ statement for( init-statement; conditions; loop-statements ), which is fancy wrapper for a while() loop.
There needs to be an instance of some kind of data type to be the iterator. If the NODE type overloads FOR/NEXT, then the iterator must be an instance of NODE type - which means copying / destructing an instance of NODE on each iteration.
fbc FOR/NEXT statements and therefore FOR/NEXT overloads for TYPESs work best with data types that have a value that can be compared with each other to know if it is higher or lower.
It is trickier for something like a singly-linked list. At some point the iterator in the FOR/NEXT loop has to be incremented to something that is larger or past the highest iteration value possible. In the case of a linked list it would be NULL or some kind of sentinel instance.
The only way I can think of to avoid an extra instance of NODE when used in a FOR/NEXT overload is to work with an instance of NODEITERATOR which could be a simple pointer to the NODE instance. And I've given an example in my last post.