It can't repeat, because I'm not simply using the number as an index, I'm using the number to start from the beginning of the array, and walk down it, counting the empty (unused) spots. When my count reaches the same number as the "where" spot, then I put it there. Here:
Code:
int array[ 5 ] = { 0 };
...
where = 2;
array[ 0 ] == empty, so "where count = 1"
array[ 1 ] == empty, so "where count = 2"
since where == where count, we now know to stop looking, and use this spot.
where = 2
array[ 0 ] == empty, so "where count = 1"
array[ 1 ] != empty, so "where count = 1" still. We can't use this, so don't count it.
array[ 2 ] == empty, so "where count = 2"
since where == where count, we now know to stop looking, and use this spot.
I didn't say it was easy, or the best way. I said it was my favourite way.
Quzah.