...
Compliant Solution (Zune 30)
This proposed rewrite is provided by \[[http://www.aeroxp.org/2009/01/lesson-on-infinite-loops]\]. The loop is guaranteed to exit, as {{Wiki Markup days}} decreases for each iteration of the loop, unless the {{while}} condition fails, and the loop consequently terminates.
| Code Block | ||
|---|---|---|
| ||
#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);
}
|
...