I wonder, what implementation is better from reading and performance sides.
1)
for (DateTime
dayStart = GetDayStart(today),
dayEnd = GetDayEnd(today);
dayStart < endOfPeriod;
dayStart = dayStart.AddDays(1), dayEnd = dayEnd.AddDays(1))
{
// ...
}
2)
DateTime dayStart = GetDayStart(today),
dayEnd = GetDayEnd(today);
while (dayStart < endOfPeriod)
{
// ...
dayStart = dayStart.AddDays(1);
dayEnd = dayEnd.AddDays(1);
}
3) Or, may be any another?
Thanks in advance.
For readability I would go with the second choise. The
forstatement is great for simpler loops, but it gets harder to follow when it gets more complicated.For performance there should be no difference at all. The compiler will likely produce the exact same code from the two different source codes.