Cags
Contributor
I was recently browsing through a book on C# 2.0 and came across an example of using a for loop to create an infinite loop. I'm not sure why you'd want to, incidently neither was the book, it just listed it incase you came across it. But has anyone ever come across this syntax.
[edit]I used the code tags because the cs tags couldn't cope the for statement (it tried to load a picture). Also note it's not C# 2.0 specific, it does work in 1.1.[/edit]
Code:
for(;;)
{
// do something
// obviously you'd want to check for an exit clause
}
// just for clarification purposes c# evaluates all the statements as true,
// thus producing the same outcome as this
while(true)
{
// do something
// obviously you'd want to check for an exit clause
}