number ranges

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


On Mon, Jan 17, 2022 at 10:35:30PM +0000, forkit via Digitalmars-d-learn wrote:
> 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. ;-)
[...]
> 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."

:-D  If *I* were to write a compiler, it'd come with a GC built-in. It'd
throw up 90% of programs you feed it with the error "this program is
garbage, please throw it away and write something better". :-D


T

-- 
If blunt statements had a point, they wouldn't be blunt...


More information about the Digitalmars-d-learn mailing list