How to reverse the order in a FOR loop

前端 未结 12 617
滥情空心
滥情空心 2020-12-31 06:16

I\'ve a simple FOR statement like this:

var num = 10,
    reverse = false;

for(i=0;i

when rever

12条回答
  •  情书的邮戳
    2020-12-31 06:44

    var num = 10,
    reverse = false;
    
    if(!reverse) for( var i=0;i

    EDIT:

    As noted in the comments below, if i is not declared elsewhere and you do not intend for it to be global, then declare it with the other variables you declared.

    And if you don't want to modify the value of num, then assign it to i first.

    var num = 10,
    reverse = false,
    i;
    
    if(!reverse) for(var i=0;i

提交回复
热议问题