Thread overview
Infinity loop with dates comparison
Aug 11, 2015
Suliman
Aug 11, 2015
anonymous
Aug 11, 2015
cym13
Aug 11, 2015
H. S. Teoh
August 11, 2015
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);
	}
August 11, 2015
On Tuesday, 11 August 2015 at 19:56:02 UTC, Suliman wrote:
> Date startDate = Date.fromISOExtString("2014-08-01");
[...]
> 	Date nextday;
>
> 	while (nextday < currentDate)
> 	{
> 		nextday = startDate + 1.days;
> 		writeln(nextday);
> 	}

startDate doesn't change, so every iteration just sets nextday to 2014-08-01 + 1 day = 2014-08-02.
August 11, 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);
 	}

August 11, 2015
On Tue, Aug 11, 2015 at 07:56:00PM +0000, Suliman via Digitalmars-d-learn wrote: [...]
> 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;
                          ^^^^^^^^^
Because you're always computing from startDate, which is constant. That
should be 'nextday' instead.


> 		writeln(nextday);
> 	}


T

-- 
Making non-nullable pointers is just plugging one hole in a cheese grater. -- Walter Bright