yangnianbing110 2015-07-24 03:19 采纳率: 0%
浏览 2672

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?

  • 写回答

7条回答

  • Soulic 2015-07-24 06:17
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作