number ranges

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Jan 17 22:28:10 UTC 2022


On Mon, Jan 17, 2022 at 10:22:19PM +0000, forkit via Digitalmars-d-learn wrote:
[...]
> I think it's fair to say, that I'm familiar with 0-based indexing ;-)
> 
> my concern was with the 1..5 itself.
> 
> In terms of what makes sense, it actually makes more sense not to use
> it, at all ;-)

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

-- 
Change is inevitable, except from a vending machine.


More information about the Digitalmars-d-learn mailing list