C# for loop syntax

前端 未结 4 1091
别那么骄傲
别那么骄傲 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:12

    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 }
    

提交回复
热议问题