What does while (i & # 8594; 0) mean?

Sorry if this is a stupid question, but I can not find the answer anywhere.

How does the following code work? (I understand that it crosses the elements els)

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

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

+4
source share
4 answers

It should be read as

i-- > 0

So what really happens

  • the value iwill be checked if it is greater than 0, if it is true, then control will go into the block while, if it is false while, the block will be skipped.

  • i , .

for, ,

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

, ++, -- .

+5

,

while((i--) > 0)

- . ++, ,

while (x --\
            \
             \
              \
               > 0) //i goes down to zero!

-

, -

var i=3;
while(i-->0){
     console.log(i);
}

2
1
0
+4

. ,

while (i--  >  0) {
0

Actually the code should be:

while (i-- > 0) {

where the loop will be executed if the value after decreasing the variable is igreater than zero.

0
source

All Articles