number ranges

forkit forkit at gmail.com
Mon Jan 17 22:35:30 UTC 2022


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."



More information about the Digitalmars-d-learn mailing list