Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Ranges for for loops was a long time coming. Some C programmers just completely lost their shit at having to use a while loop for some reason. It was such a common complaint that we invented stuff like the following as a joke, that of course became something people actually used because internet gonna internet:

  for(@as([10]void, undefined)) |_, idx| {
    _ = idx;
  }
Which, for those unfamiliar with Zig, has `for` iterate over an 'array' of 0-bit values and capture the index while throwing out the value (which would always be 0 because that's the only value a 0-bit type can represent).

The implementation of this proposal brings with it the additional benefit of making index capturing less mysterious.



I suspect the real reason behind "some C programmers losing their shit" was being forced to introduce a new variable into the outer scope, or to use extra braces around your loop -- both are distasteful hacks, according to some.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: