Answer 1
This is not a compiler bug, though I will agree that it would be nice if the compiler could provide a meaningful warning in this situation.
The problem is really only the last line, which is a completely separate statement in C#. This:
for (int i = 1; i <= LIMIT; i++)
{
Total = Baby;
Adult = Adult + Baby;
Baby = Adult - Total;
Console.WriteLine("\n\n{0}\t{1}\t{2}\t{3}", Month, Adults, Babies, Totals);
Console.WriteLine("\n\n{0}\t{1}\t{2}\t{3}", i, Baby, Total, Adult);
Console.Write("_____________________________");
} while (Adult < CAGES) ;
Can be rewritten (identically) as:
// for loop first...for (int i = 1; i <= LIMIT; i++)
{
Total = Baby;
Adult = Adult + Baby;
Baby = Adult - Total;
Console.WriteLine("\n\n{0}\t{1}\t{2}\t{3}", Month, Adults, Babies, Totals);
Console.WriteLine("\n\n{0}\t{1}\t{2}\t{3}", i, Baby, Total, Adult);
Console.Write("_____________________________");
}
// Now there's a while loopwhile (Adult < CAGES) ;
The issue here has nothing to do with the for loop - it's really just the while loop body.
That can be rewritten identically as:
// The semi colon effectively creates an empty blockwhile (Adult < CAGES)
{
}
Now, this may seem like a useless statement - however, it is not necessarily incorrect.
If "Adult" or "CAGES" is a volatile variable, it's possible a separate thread could be modifying them. Granted, a spin loop like this is a very bad idea (for many reasons), but technically, it could be creating a situation where there is a block until
a condition is met.
Granted, this would be bad code, even if it were done on purpose, and there would be many better ways to clean it up. I, personally, would like to see the compiler add a warning for empty loop bodies, but it is 100% correct code as far as the C# language
specifications, so it's not a bug - more of a feature request.