Rewrote using do while loop instead of for loop.

Makes it more sensible, since do checks condition at the end and for
checks at the start. I was using [i-1] in the array to check the
previously written element but realized that is kind of freaky because
when i=0...what is it checking?