Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Compliant Solution (Zune 30)

Wiki MarkupThis proposed rewrite is provided by \[[http://www.aeroxp.org/2009/01/lesson-on-infinite-loops]\]. The loop is guaranteed to exit, as {{days}} decreases for each iteration of the loop, unless the {{while}} condition fails, and the loop consequently terminates.

Code Block
bgColor#ccccff
#define ORIGINYEAR 1980 
UINT32 days = /* input parameter */
int year = ORIGINYEAR;
/* ... */

int daysThisYear = (IsLeapYear(year) ? 366 : 365);
while (days > daysThisYear) {
  days -= daysThisYear;
  year += 1;
  daysThisYear = (IsLeapYear(year) ? 366 : 365);
}

...