C# for loop syntax

前端 未结 4 1095
别那么骄傲
别那么骄傲 2021-01-18 18:56

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

4条回答
  •  余生分开走
    2021-01-18 19:32

    for (;;)

    Short answer: It is an infinite loop which is equivalent to while(true)

    Long answer: for (initializer; condition; iterator) Structure of the for statement

    • initializer block: Do not initialize variable.
    • condition block: with no condition (means execute infinitely) => while true
    • iterator block: with no operation to any variable (no iterator)

    for(;;) example from official documentation

提交回复
热议问题