digitalmars.D.learn - Infinity loop with dates comparison
- Suliman (17/17) Aug 11 2015 The code look very trivial, but I am getting infinity loop like:
- anonymous (4/11) Aug 11 2015 startDate doesn't change, so every iteration just sets nextday to
- cym13 (10/27) Aug 11 2015 This isn't a D problem, you just always set nextday to the same
- H. S. Teoh via Digitalmars-d-learn (8/23) Aug 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); }
Aug 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.
Aug 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); }
Aug 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
Aug 11 2015