I was going through some JavaScript code when a loop structure caught my eye. It wasn't anything particularly special, rather it iterated in a manner different from what I do. When I need to loop something that isn't dependent on order, I typically count up, iterating from beginning to end, like so:
do
{
// I feel like I'm going in circles
i++;
} while (i < length)
However, this JavaScript function counted down, looping from end to beginning.
var i = data.length - 1;
if(i >= 0)
{
do
{
// Around and around, we go
}while(i--)
}
Is there any advantage to counting downward or is it just up to developer preference?