Infinite loop application - for(;;)

后端 未结 5 719
一生所求
一生所求 2020-12-22 03:29

I am trying to understand the concept behind the for loop example

for (;;)
{
//write code
}

I understand what it does and how it\'s the sa

5条回答
  •  时光说笑
    2020-12-22 04:04

    while(abortRequested)
    {
      // ....
    }
    

    is almost equivalent to

    while(true)
    {
       // ...
    
       // ... dozens of lines of code ...
    
       if(abortRequested)
         break;
    
       // prepare next iteration
    }
    

    Alternatively this might also run in a daemon thread which automatically gets terminated when all non-daemon threads are done. So the semantic of these constructs generally is:

    Should keep running forever by default, unless some explicit termination event is received.

提交回复
热议问题