Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "for(;;)" do in C#?

Tags:

I've seen this on occasion in books I've read. But I've found no explanation.

for (;;)
{
  // Do some stuff.
}

Is it kind of like "while(true)"? Basically an endless loop for polling or something? Basically something you'd do until you intentionally break the loop?

like image 645
IAmAN00B Avatar asked Jun 11 '09 17:06

IAmAN00B


2 Answers

Is it kind of like "while(true)"?

Yes. It loops forever.


Also note the comment by Andrew Coleson:

Languages like C don't have built-in boolean primitives, so some people prefer for(;;) over while(1)

like image 85
Joel Coehoorn Avatar answered Nov 09 '22 04:11

Joel Coehoorn


Yes.

In a for if nothing is provided:

  • The initialisation does nothing.
  • The condition is always true
  • The count statement does nothing

It is equivalent to while(true).

like image 36
Coincoin Avatar answered Nov 09 '22 06:11

Coincoin