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

When you look at how infinite loops should be implemented, you mostly see this approach:

while :
do
  # loop infinitely
done

But I just don't understand the use of : here. Wouldn't it be better to use:

while true
do
  # loop infinitely
done

?

This question is related to bash

The answer is


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.