Siemel Naran said:
Good. But the problem is that in the original code, both Sunday and
Saturday map to zero. In that case I don't think there's any way to iterate
because a value of zero could mean either day, so the next day is either
Sunday or Monday, we don't know which.
The next day would be Monday, because the next value is (0+1), which is 1,
which is Monday. So your loop would start at Saturday/Sunday (the same!),
followed by Monday, then Tuesday, ...
So, can you think of other solutions?
It depends on what you want to do.
If you want to loop over the enumeration, and have that loop include both
Saturday and Sunday as *different* loop values (i.e., you want them to be
handled in seperate passes through the loop), then it's simply not possible,
because you've defined them as the *same* value. Saturday and Sunday are
identical.
You could loop, using integers that start at Sunday (or Saturday) and end at
(after) Friday, but when that integer is 0, you won't be able to tell if
it's Saturday or Sunday, because it will simply be zero, which is valid for
both Saturday and Sunday. So that will work only if you can live with
treating day 0 as one day, ignoring whether it was intended to be Saturday
or Sunday. (Call it "Weekend"?
)
If you need Saturday and Sunday to be handled in different passes through
the loop, then they absolutely *must* have different values. Perhaps you
could define a separate enumeration where they have different values?
One other idea: don't loop. You have only seven cases, right? Why not
handle them explicitly, instead of via a loop? So instead of something like
for (i = Saturday; i <= Friday; ++i)
DoOneDay(i);
write
DoSaturday();
DoSunday();
DoMonday();
DoTuesday();
etc.
-Howard