[Which is faster, (1) or (2)?I thought of this while looking at
for (;;) {
//Something to be done repeatedly
}
I've seen a lot of codes like this, but I haven't seen them write in while(true)
.
I think while(true)
is more readable if you're going to use it. Why is that?
Are you writing a for statement because for(;;)
is faster than while(true)
?
Both have the same assembly code, so their performance is the same.
The reason why for(;)
is usually used more is
This is because the compiler warns you that "loop condition is constant" in while(true)
Because for(;)
is "no condition" and is closer to infinite loop. Doesn't (while(true)
seem to have the condition true
? ;)
© 2024 OneMinuteCode. All rights reserved.