while(i - > 0)是什么意思? [英] What does while (i --> 0) mean?
问题描述
如果这是一个愚蠢的问题,我道歉,但我无法在任何地方找到答案。
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
所以,真正发生的是,
-
值
i
将被检查是否大于0,如果为真则控制将进入while
block,如果为false,则
块将被跳过。
value of
i
will be checked if it greater than 0, if it is true then control will enter thewhile
block, if it is falsewhile
block will be skipped.
无论哪种方式, i
的值将在检查条件后递减,立即。
Either way, the value of i
will be decremented, immediately after the condition is checked.
当我们使用计数器运行循环时,使用进行
循环总是更好,就像这样
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屋!