Infinity loop with dates comparison
cym13 via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Aug 11 13:06:06 PDT 2015
On Tuesday, 11 August 2015 at 19:56:02 UTC, Suliman wrote:
> The code look very trivial, but I am getting infinity loop like:
> 2014-Aug-02
> 2014-Aug-02
> 2014-Aug-02
> ...
> 2014-Aug-02
>
>
> Date startDate = Date.fromISOExtString("2014-08-01");
>
> Date currentDate = to!(Date)(Clock.currTime()-1.days);
> //because current day is not finished
>
> writeln(startDate);
> writeln(currentDate);
>
> Date nextday;
>
> while (nextday < currentDate)
> {
> nextday = startDate + 1.days;
> writeln(nextday);
> }
This isn't a D problem, you just always set nextday to the same
value that doesn't change (startDate + 1.days).
Maybe what you meant was:
nextday = startDate;
while (nextday < currentDate)
{
nextday = nextday + 1.days;
writeln(nextday);
}
More information about the Digitalmars-d-learn
mailing list