Hi
The forever macro in Qt is for(;;) .Is there any advantage of using while(true) to for(;;).
Thanks.
Printable View
Hi
The forever macro in Qt is for(;;) .Is there any advantage of using while(true) to for(;;).
Thanks.
It's for efficiency. Compiler may generate more assembler instructions for while(true), because there is a judgment. However, if you leave the middle parameter of for( ; ; ) empty, compiler will generate a jump instruction without any judgment.
But, modern compiler should be capable to recognize the forever true parameter of while() and generate the same assembler instructions as for( ; ; ).
So, use both as you like.