I wanted to iterate through a date range, so I initially tried:

That wouldn't compile, which is fair enough I guess.

So I tried a for loop:
for (auto i = Date(2016,1,1); i < Date(2018,1,1); i+=dur!"days"(1)){}

That seemed to work fine, but I remember reading "for loops are bad" somewhere. So I looked for a range type mechanism, and I think it's this: foreach (i; Interval!Date (Date(2016,1,1),Date(2018,1,1)).fwdRange ( (a) { return a+dur!"days"(1); })){}

My question is if the third way is the proper way of stepping through a period of time? It just seems quite complicated to me.



Reply via email to