C# for loop syntax

  • A+

I'm working on some C# code that has loop syntax that I've never seen before:

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

What does a for loop without a init; condition; or increment do? By the way it's really hard to find meaningful search results on the internet for "for (;;) c#" on any search engine I tried.



The syntax of a for loop is thus:

for (condition; test; action) 

Any one of those items can be omitted (per the language spec). So what you've got is an infinite loop. A similar approach:

while (true) { // do some stuff } 


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: