News for hackers. Stuff that matters.
Re:Why do arrays start at 0? by 10000truths on Wednesday August 24, 2022 @02:23PM (#32583653)

  for (size_t i = 0; i < length; i++) {
      size_t j = (length - 1) - i;
      ...
  }
EDIT: change i to j
Re:Why do arrays start at 0? by yuliyp on Wednesday August 24, 2022 @02:29PM (#32583725)
That's quite broken (you'd want a different variable inside the body, vs clobbering the iteration counter, else this would process the last item in your list, then exit).
Re:Why do arrays start at 0? by rabbidruster on Wednesday August 24, 2022 @02:32PM (#32583788)
I hope you haven't done this anywhere.

Makes my brain hurt, but I think this will only run through the loop one time looking at the last element of the array.

Re:Why do arrays start at 0? by unwind on Wednesday August 24, 2022 @02:30PM (#32583758)
Uh no don't reassign the loop variable in the inner scope. Use:

    const j = (length - 1) - i;
in that case. Much safer.
Re:Why do arrays start at 0? by Banana699 on Wednesday August 24, 2022 @03:08PM (#32584252)
You should save the old value of i somewhere and restore it back at the very end of the loop. Or simply define a new j like another comment says.