C# for loop syntax

  • A+
Category:Languages

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.

-Eric

 


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 } 

Comment

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