3

Possible Duplicate:
In C# is a for(;;) safe and what does it really do?

So i recently came across something ive never seen before..

        for (; ; )
        {

        }

What is exactly happening when the feilds are left blank like that?

Community
  • 1
  • 1
caesay
  • 16,404
  • 14
  • 91
  • 156
  • almost a dup of http://stackoverflow.com/questions/1401159/for-or-while-true-which-is-the-correct-c-infinite-loop – Denis Ivin Nov 30 '10 at 05:25

3 Answers3

13

It's an infinite loop.

Somewhere inside there should be a break; statement, or possibly an exception thrown in order for control to pass beyond the loop.

You could also achieve the same thing (probably more obviously) by doing

while (true)
{
    // do stuff
}
Jon
  • 15,608
  • 8
  • 51
  • 62
2

This is an infinite loop, almost equivalent to a while(true) loop.

The break condition is not there in between the two semicolons, therefore, it must be there somewhere in the loop body.

Aamir
  • 14,434
  • 6
  • 41
  • 66
1

That's an infinite for loop.

tpv
  • 153
  • 9