4 ms·
It's not the most concise way to iterate over a sequence of numbers from 1 to 9. Worse than that, it suggests that there may be a number missing somewhere in th
by fauigerzigerk 11y ago
It's not the most concise way to iterate over a sequence of numbers from 1 to 9. Worse than that, it suggests that there may be a number missing somewhere in the middle. You have to scan the entire sequence with your eyes to be sure.
for (int i = 1; i <= 9; ++i)
is both more concise and requires less thinking to know what's going on.
- sjolsen 11y agoThat the data he chose can be expressed as a range is utterly inconsequential. The values are never even used. In all likelihood, the author just wrote for (auto item : {}) and then filled in the first sequence of numbers that popped into his head.
- fauigerzigerk 11y ago>That the data he chose can be expressed as a range is utterly inconsequential It could be, but we don't know that. And that's exactly my point. The syntax he uses forces us to think and even speculate about that. So for the particular sequence he chose for his example, it would be less ambiguous to generate the range algorithmically.