Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of "for (;;)" in a C# application?

Tags:

c#

for-loop

I've been looking through some sample source code for an application I use and I came across this line:

for (;;)
{
// The rest of the application's code
}

It looks like this is to create an infinite loop, but I'm not familiar with ";;" and it's very hard to Google unfortunately.

like image 834
JuniorDeveloper1208 Avatar asked Jan 05 '11 13:01

JuniorDeveloper1208


1 Answers

Yes, that is an infinite loop. It's an ordinary for loop with no condition expression.

From the documentation for for:

All of the expressions of the for statement are optional; for example, the following statement is used to write an infinite loop:

for (; ; )
{
    // ...
}
like image 64
Mark Byers Avatar answered Oct 14 '22 03:10

Mark Byers