Possible Duplicates:
Is “for(;;)” faster than “while (TRUE)”? If not, why do people use it?
for ( ; ; ) or while ( true ) - Which is the Correct C# Infinite Loop?
Is there any appreciable difference between while(true)
(or while(1)
) and for(;;)
? Would there be any reason to choose one over the other?
The while loop in python runs until the "while" condition is satisfied. The "while true" loop in python runs without any conditions until the break statement executes inside the loop.
no functional difference at all, just a matter of taste.
While loop is used to execute a block of code repeatedly until given boolean condition evaluated to False. If we write while True then the loop will run forever.
Why does while distinguish the two? It's emitting a LOAD_GLOBAL (True) for each True , and there's nothing the optimizer can do with a global. So, while distinguishes 1 and True for the exact same reason that + does.
With optimizations enabled, they will compile identically.
You should use whichever one you find more readable.
No. I think for(;;)
looks nicer. But they're the same.
Also see Is "for(;;)" faster than "while (TRUE)"? If not, why do people use it?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With