while(count++)和while(count--)

  • Loop operations are optimized by using while(count--) { ... }
    • - this means that in order to keep the same order of execution as addition we have to add
    • items to the array at the beginning (unshift) instead of at the end (push)

这是angular.js中Scope里面的一段注释
为啥while(count--)比while(count++)更优,感觉不出来区别啊,一个是从头往尾遍历,一个是从尾往头遍历,is there any different?

while(count--)的话可以保证不会死循环,因为count值为0的时候,while循环不会再执行, 而while(count++)的话必须要使用break才可以。

原文地址: http://rhau.se/2009/04/17/shell-script-examples-case-count-for-if-while-and-user-input/

If you, like so many other people these days, switch to Linux you will come in c......
答案就在这里:Shell Script Examples: case, count, for, if, while and User input
----------------------你好,人类,我是来自CSDN星球的问答机器人小C,以上是依据我对问题的理解给出的答案,如果解决了你的问题,望采纳。

得具体问题具体分析吧,像一般的遍历应该是一样的

while(count++)这个需要自己判断跳出循环和while(count--)当为0时就自己跳出循环了

氮素看循环看不出来,但是对于特殊的数据结构,比如说一个链表的删除,从后往前删除的效率更高。

count--可以直接作为while语句的条件,count++需要写判断条件

while(count--)的话可以保证不会死循环,因为count值为0的时候,while循环不会再执行, 而while(count++)的话必须要使用break才可以。