Which is the correct C# infinite loop, for (;;) or while (true)?
c#, infinite-loop
Solution
while(true)
{
}
Is always what I've used and what I've seen others use for a loop that has to be broken manually.
Problem
Back in my C/C++ days, coding an "infinite loop" as ``` while (true) ``` felt more natural and seemed more obvious to me as opposed to ``` for (;;) ``` An encounter with PC-lint in the late 1980's and subsequent best practices discussions broke me of this habit. I have since coded the loops using the `for` control statement. Today, for the first time in a long while, and perhaps my first need for an infinite loop as a C# developer, I am facing the same situation. Is one of them correct and the other not?