while (i --> 0) 是什么意思? [英] What does while (i --> 0) mean?

查看:105
本文介绍了while (i --> 0) 是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果这是一个愚蠢的问题,我深表歉意,但我无法在任何地方找到答案.

I apologize if this a stupid question, but I cannot find the answer anywhere.

下面的代码是如何工作的?(我意识到它会遍历 els 的元素)

How does the following code work? (I realize that it loops over the elements of els)

var i = els.length;
while (i --> 0) {
    var el = els[i];
    // ...do stuff...
}

我不知道 --> 是什么意思.没有相关文档.有人能指教我吗?

I have no idea what --> means. There is no documentation for it. Can someone enlighten me?

推荐答案

它应该被理解为

i-- > 0

所以,真正发生的是,

  1. i 的值是否大于 0 将被检查,如果为真则控制进入 while 块,如果为假while 块将被跳过.

  1. value of i will be checked if it greater than 0, if it is true then control will enter the while block, if it is false while block will be skipped.

无论哪种方式,i 的值都会在条件检查后立即递减.

Either way, the value of i will be decremented, immediately after the condition is checked.

使用 for 循环总是更好,当我们使用计数器运行循环时,就像这样

Its always better to use for loop, when we run a loop with a counter, like this

for (var i = els.length - 1; i >= 0; i -= 1) {
    ...
}

请阅读更多关于 ++-- 是否可以或不是.

Please read more about whether ++, -- is okay or not.

这篇关于while (i --> 0) 是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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