"而:"与"而真正的" [英] "while :" vs. "while true"

查看:264
本文介绍了"而:"与"而真正的"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您怎么看待无限循环应该实现,你看大部分这种方法:

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

推荐答案

从手动:

:[参数]
            没有效果;该命令不执行任何超出扩大参数和执行任何指定的
            重定向。零退出$ C $返回c。

: [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

看看这个答案:什么是'的宗旨:'(冒号)GNU Bash的内建

这篇关于"而:"与"而真正的"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆