3 ms·
The C++20 version is still clearly inferior to the Python and Lua examples because you still have to manually increment the counter in the loop body. IMO the si
by WCSTombs 3mo ago
The C++20 version is still clearly inferior to the Python and Lua examples because you still have to manually increment the counter in the loop body. IMO the sibling comment by HarHarVeryFunny has a much better C++ equivalent for this idiom, even if it's slightly more verbose.
- Gualdrapo 3mo ago> you still have to manually increment the counter in the loop body It doesn't look like that to me, the ++i thing seems to be just to start printing the array from 1 (I don't know how things are in Python nowadays but I know in Lua arrays start at 1, so there's no need for something like this in there), the value of i is still increasing without telling it explicitly to do so
- sheept 3mo agoPython is 0-indexed. In OP's example, the start parameter makes i start at 1. Their C++17 example prints starting from 0. Probably a mistake. If you look at the linked page for C++20[0], other types can be put in the initializer statement, so it's unlikely the loop auto-increments. [0]: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0614r0.html https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p06...
- kbenson 3mo agoSo, it's just a while loop in a for loop's clothing? That's not going to be confusing for people at all...
- comex 3mo agoNo, it's a for loop that happens to include an unrelated variable declaration.
- kbenson 3mo agoAh, I see. The increment is so they can manually handle the included feature of the other cases, which number of the iteration you're on. Nice that it will automatically loop across a collection, annoying that they couldn't go the whole way and you need to deal with it manually.
- moron4hire 3mo agoNo, the increment is necessary to keep the counter going. The choice of pre-increment versus post-increment handles the "start at 1" issue you mentioned, but it isn't auto incrementing.
- deleted 3mo ago[deleted]