News for hackers. Stuff that matters.
Re:Why do arrays start at 0? by operator-name on Wednesday August 24, 2022 @02:31PM (#32583765)
In that specific case I'd do the following:

    for (size_t i = n; i-- > 0 ;) ...
Or count from `length` to 1, but subtract 1 in the loop body, or count up and subtract the length in the loop body. Any modern compiler should be able to optimise these to be equivalent.

In the majority of cases, counting down is not necessarily. Nor is ordered iteration. Most languages have a `for each` style syntax that's preferable anyway.

Re:Why do arrays start at 0? by cylon13 on Wednesday August 24, 2022 @02:38PM (#32583866)
Ah yes, the goes-to operator -->
Re:Why do arrays start at 0? by tomjakubowski on Wednesday August 24, 2022 @02:50PM (#32584020)
And the wink operator, so the compiler knows you know the deal
Re:Why do arrays start at 0? by bmacho on Thursday August 25, 2022 @02:56AM (#32590479)
I like how GP is called "operator-name" and instead of doing himself, he makes others joking with operator names. Although I'm not sure if it's altruism or highly manipulative behaviour.
Re:Why do arrays start at 0? by wizofaus on Wednesday August 24, 2022 @04:33PM (#32585362)
Gold - have an upvote!
Re:Why do arrays start at 0? by divbzero on Wednesday August 24, 2022 @03:11PM (#32584307)
Or alternatively:

  size_t i = length;
  while (i--) ...
Re:Why do arrays start at 0? by jecel on Thursday August 25, 2022 @04:59PM (#32599864)
Unless I am remembering C wrong, this would work but the

   for (size_t i = length; i-- > 0 ; ) ...
that several other people posted would not execute for index 0. Shouldn't it be this instead?

   for (size_t i = length; --i > 0 ; ) ...