Strange For iterator behavior for TSet

I have TSet structure with 10000 elements. For iterator must iterate through 0-9999 element but it iterates 10000th element

There is nothing strange about it. Think like this, when iterates 0th element ++n will be 1 so in 9999th iteration ++n will be 10000. if you want n to be 0 for first element, n should start from -1.

Please look at the breakpoint. It is above ++n. And 10000th element has garbage values