2 ms·
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 com
by AnIdiotOnTheNet 4y ago
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.
- gonzus 4y agoI 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.