34

Possible Duplicates:
Is “for(;;)” faster than “while (TRUE)”? If not, why do people use it?
for ( ; ; ) or while ( true ) - Which is the Correct C# Infinite Loop?

Is there any appreciable difference between while(true) (or while(1)) and for(;;)? Would there be any reason to choose one over the other?

Community
  • 1
  • 1
kylan
  • 513
  • 1
  • 4
  • 8
  • possible duplicate of [for ( ; ; ) or while ( true ) - Which is the Correct C# Infinite Loop?](http://stackoverflow.com/questions/1401159/for-or-while-true-which-is-the-correct-c-infinite-loop) (C# for this question, but the answers also address C++) – Adam Robinson Sep 27 '10 at 20:33

2 Answers2

33

With optimizations enabled, they will compile identically.

You should use whichever one you find more readable.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
6

No. I think for(;;) looks nicer. But they're the same.

Also see Is "for(;;)" faster than "while (TRUE)"? If not, why do people use it?

Community
  • 1
  • 1
Charles Salvia
  • 52,325
  • 13
  • 128
  • 140