tags:

views:

32

answers:

2

OK its late so I must be doing something stupid, but myreduction for loop which works fine in c# does not work in javascript. The loop is NEVER entered. What have I missed?

var count = 12;
var j = count - 3
    for (i = count; i<1 ; i--)
    {
        if (i % 3 == 0)
            break;
        else
            j = i - 1;
    }

alert(j);

In this case I am expecting the following:

12 -> 9;
11 -> 7;
10 -> 7;
9 -> 6;
8 -> 4;
7 -> 4;
+4  A: 
for (i = count; i>1 ; i--)

??

You want the loop to continue while i is greater than 1 (perhaps this might differ with this logic change)

spender
cheers, must sleep! I had i == 0 in my c# instead!
tigermain
A: 

You can try :

for (var i = count; i > 1 ; i--) {
   // code
}
fastcodejava