C# for loop syntax

前端 未结 4 1124
别那么骄傲
别那么骄傲 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条回答
  •  梦毁少年i
    2021-01-18 19:07

    That is an infinite loop. Like you stated, it will run until a part of it breaks (throws an exception or otherwise exists the loop) or the machine runs out of resources to support the loop.

    for (;;)
    {
       //do stuff
    } 
    

    Is just the same as:

    do
    {
       //do stuff
    }while (true)
    

    while(true)
    {
       //do stuff
    }
    

提交回复
热议问题