It makes sense that if you pass 0 to the function it would do something strange.
LoopIndex gives you a number as the loop moves from the start index to the end index.
So in this case, if the start index = 0 and the end index = 0 - 1, then the for loop will be executed two times. The first time loopIndex will be 0 and the second time loopindex will be -1.
If you plug those number in the calculation it is doing to place the bars, you will see it places the first one with no offset, and the second one to the left of the first.
The function should have a special case for 0, so that it doesn't even go in the for loop and just exits early after destroying all the existing instances.