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

查看:338
本文介绍了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 block,如果为false ,则块将被跳过。

  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.

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

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天全站免登陆