On Monday, 17 January 2022 at 22:28:10 UTC, H. S. Teoh wrote:

If I ever needed to foreach over 1-based indices, I'd write it this way in order to avoid all confusion:

        foreach (i; 1 .. 5 + 1)
        {
        }

This will immediately make whoever reads the code (i.e., myself after 2 months :D) wonder, "why +1?" And the answer will become clear and enlightenment ensues. ;-)


T

If I were able to write a compiler, my compiler would warn you:

"This is ill-advised and you should know better! Please rewrite this."

Reply via email to