Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"while :" vs. "while true" [duplicate]

Tags:

bash

People also ask

Is while true the same as while 1?

It distinguishes 1 and True in exactly the same way that the + example does. 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.

What is the difference between while and while true?

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.

Is while 1 the same as while true in C?

There is no difference once the program is compiled. Here are some excerpts from three C programs and the corresponding generated assembly for all of them. Since they all do exactly the same thing, clearly there is no technical advantage of any of them (at least if you are using gcc ).

Does while true run forever?

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.


from manual:

: [arguments] No effect; the command does nothing beyond expanding arguments and performing any specified redirections. A zero exit code is returned.

As this returns always zero therefore is is similar to be used as true

Check out this answer: What Is the Purpose of the `:' (colon) GNU Bash Builtin?


The colon is a built-in command that does nothing, but returns 0 (success). Thus, it's shorter (and faster) than calling an actual command to do the same thing.