News for hackers. Stuff that matters.
Re:Almost Always Unsigned by amavect on Thursday July 09, 2026 @08:04PM (#48854146)
Post-increment inverts to pre-decrement, but for-loops don't support proper syntax sugar for pre-decrement.

  for(size_t i = 0; i < size; i++){
    // loop body
  }
  for(size_t i = size; i > 0;){ i--;
    // loop body
  }
Re:Almost Always Unsigned by teo_zero on Friday July 10, 2026 @01:20AM (#48855998)
Put the "--" in the condition. It's less ugly.
Re:Almost Always Unsigned by amavect on Friday July 10, 2026 @11:44AM (#48861483)
Pedantically, that doesn't properly invert post-increment in the loop step. It decrements one extra time. If I need to use the loop index after the loop, then decrementing in the condition would cause problems.

  size_t i = size;
  while(i-- > 0){
    // loop body, possibly break
  }
  use(i); // i wraps below 0

  size_t i = size;
  while(i > 0){
    i--;
    // loop body, possibly break
  }
  use(i); // i doesn't wrap
Practically, i leaves the for-loop scope, so most never encounter this problem.